简体   繁体   中英

Need to Animate image button

I have my Android app with a login activity . when the user gets logged in i need another activity which contains four image buttons and the main need is that when the activity comes up the buttons must slide to the middle from the right side . Can anyone help me with the codes

Step 1.make anim folder and create xml with name slide_right.xml and put the below content

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromXDelta="100%p" 
        android:toXDelta="0"
        android:duration="500" />

Step 2.Into the onCreate() method of your MainActivity class, load animation and set it to your view buttons

Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_right);
yourbutton.startAnimation(animation);

You can also use View Flipper

<ViewFlipper
    android:id="@+id/myFlipper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:animateFirstView="true"
    android:autoStart="true"
    android:flipInterval="500"
    android:inAnimation="@android:anim/fade_in"
    android:outAnimation="@android:anim/fade_out" >
<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:src="@drawable/myImage" />
</ViewFlipper>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM