how to animate button with finger ontouch event an

2019-04-02 14:16发布

问题:

I want to move a button with finger moving on and screen. but i can't found any help for this animations with finger motion. i make a fake call apps in which i want to make incoming call layout like below image. how i make a receive or decline button in android:

can i use on-touch event for this animation.

              if (event.getAction()==MotionEvent.ACTION_MOVE) {

                  x=event.getX();
                  RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(300, 60);
                  params.leftMargin = (int)x;

                  btnDeclinecall.setLayoutParams(params);

                           }

                return false;
            }

i use the above codes but it doesn't work for me

回答1:

See The Code at Android's LockSCreen Slider

FYI:This is not my code, it is from android froyo source code. I also had created the slider in my app using code from above location but that was right slider, So i cant post that code because you need left slider.

so just copy Left slider part from above link and use it with little understanding.

Note:

Above link contain the best and optimized code for slider(But it contain both left and right slider).

so don't waste time anywhere else, It may look little tough in starting but Trust me just try to understand use of private Slider mLeftSlider;in the above link and that will lead you to your destination.