Wednesday, 19 September 2018

A button Long Pressed just move the 4 Images to left ,right ,top,bottom corners then, Release the button set the images in same position-Android

  1. I have a button, when button is Long pressed - move the Image view to left, right, top, bottom corners bit up.
  2. After the button is released, return the Image view to previous position.
  3. Please help me to achieve this. Thanks in advance!

    Mainactivity.java

     floatingActionButton.setOnLongClickListener(new 
     View.OnLongClickListener() 
      {
            @Override
            public boolean onLongClick(View v) {
    
                Iv1.startAnimation(animFadein1);
                Iv2.startAnimation(animFadein2);
                |Iv3.startAnimation(animFadein3);
                Iv4.startAnimation(animFadein4);
                System.out.println("in PRESSED");
                return true; 
            }
        });
    
        floatingActionButton.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch(event.getAction()){
                    case MotionEvent.ACTION_UP:
                    {
                        Toast.makeText(getApplicationContext(), "Rlesed", Toast.LENGTH_SHORT).show();
    
                        return true; 
                    }
                }
                return false;
            }
        });
    
    

Please see the example image:

https://i.stack.imgur.com/nlxqI.png

topleft.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">;
    <translate
        android:duration="500"
        android:fromXDelta="-5%"
        android:fromYDelta="-5%"
        android:toXDelta="0%"
        android:toYDelta="00%"
        android:zAdjustment="bottom"></translate>
</set>

topright.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">;
    <translate
        android:duration="500"
        android:fromXDelta="5%"
        android:fromYDelta="-5%"
        android:toXDelta="0%"
        android:toYDelta="00%"
        android:zAdjustment="bottom"></translate>
</set>



from A button Long Pressed just move the 4 Images to left ,right ,top,bottom corners then, Release the button set the images in same position-Android

No comments:

Post a Comment