K
K
kirawa2014-08-18 07:37:17
Android
kirawa, 2014-08-18 07:37:17

How to make a proper ViewPager?

I made the ViewPager work fine, but there are Buttons inside the pager, and when you try to scroll the pager, the buttons are also pressed if you hit them. On the buttons I have OnTouch something like this

@Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        switch (view.getId()){
            case R.id.btnZero:
                switch (motionEvent.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        relativeZero.setBackgroundColor(transparent);
                        setMargin(btnZero,3,3,3,3);
                        if (result != null  && result.length() <= 11){
                            result += "0";
                            txtTablo.setText(result);
                        }
                        break;
                    case MotionEvent.ACTION_UP:
                        relativeZero.setBackgroundResource(R.drawable.back_button_2);
                        setMargin(btnZero,0,0,0,3);
                        break;
                }
                break;



private void setMargin(Button btn, int left, int top, int rigth, int botom){
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) btn.getLayoutParams();
        params.setMargins(left,top,rigth,botom);
        btn.setLayoutParams(params);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2014-08-20
@DrZ0idberg

Just don't need to handle buttons via touch. You need to use OnClickListener.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question