How to translate view with smooth animation in android -
i have written peace of code perform animation. have written animation file in anim folder
my animone.xml file <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" android:fillafter="true"> <translate android:fromydelta="0%p" android:toydelta="-5%p" android:duration="1500"/></set>
and here apply animation on view linearlayout
animation animate= animationutils.loadanimation(context,r.anim.animone); subprofile.setvisibility(view.visible);//subprofile linear layout subprofile.startanimation(animate);
so when run code . change position of view without smooth sliding after specified duration. want make smooth. please help.
----------------here complete code---------------- main fragment file
<framelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.videosapp.fragments.homefragment" android:background="@drawable/background"> <relativelayout android:layout_width="match_parent" android:layout_height="match_parent"> <linearlayout android:id="@+id/my_pofile" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:layout_centerinparent="true" android:visibility="gone"> <imageview android:id="@+id/dshimg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_centerhorizontal="true" android:background="@drawable/dashboard"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="dashboard" android:layout_below="@id/dshimg" android:textcolor="@color/colortext" android:textsize="18sp" android:layout_gravity="center_horizontal" /> </linearlayout> <linearlayout android:id="@+id/podcast" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1" android:gravity="center" android:layout_centerinparent="true" android:visibility="gone"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/podcast"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="podcast" android:textcolor="@color/colortext" android:textsize="18sp" /> </linearlayout> <linearlayout android:id="@+id/photo_gallery" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1" android:gravity="center" android:layout_centerinparent="true" android:visibility="gone"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/photo_gallery"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="photo gallery" android:textcolor="@color/colortext" android:textsize="18sp" /> </linearlayout> <linearlayout android:id="@+id/social" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1" android:gravity="center" android:layout_centerinparent="true" android:visibility="gone"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/social"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="social" android:textcolor="@color/colortext" android:textsize="18sp" /> </linearlayout> <linearlayout android:id="@+id/about_us" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1" android:gravity="center" android:layout_centerinparent="true" android:visibility="gone"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/aboutus"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="know us" android:textcolor="@color/colortext" android:textsize="18sp" /> </linearlayout> <linearlayout android:id="@+id/contact_us" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1" android:gravity="center" android:layout_centerinparent="true" android:visibility="gone"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/contact_us"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="contact us" android:textcolor="@color/colortext" android:textsize="18sp" /> </linearlayout> <linearlayout android:id="@+id/setting" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1" android:gravity="center" android:layout_centerinparent="true" android:visibility="gone"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/settings"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="settings" android:textcolor="@color/colortext" android:textsize="18sp" android:layout_gravity="center_horizontal" /> </linearlayout> <linearlayout android:id="@+id/exit_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1" android:gravity="center" android:layout_centerinparent="true" android:visibility="gone"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/exit"/> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="exit" android:textcolor="@color/colortext" android:textsize="18sp" /> </linearlayout> <imageview android:id="@+id/menu_home" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/center_menu" android:layout_centerinparent="true" /> </relativelayout> <relativelayout android:layout_width="match_parent" android:layout_height="match_parent"> <!--on following linearlayout want apply animation--> <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_centerinparent="true" android:id="@+id/profile" android:visibility="gone" > <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/my_profile_icon"/> <textview android:layout_width="wrap_content" android:layout_height="match_parent" android:text="my profile" android:gravity="center_vertical" android:textcolor="@color/colortext" android:textsize="20sp" /> </linearlayout> <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="15dp" android:orientation="horizontal" android:layout_centerinparent="true" android:id="@+id/programs" android:visibility="gone" > <imageview android:layout_width="40dp" android:layout_height="40dp" android:src="@drawable/folder_icon"/> <textview android:layout_width="wrap_content" android:layout_height="match_parent" android:text="my programs" android:gravity="center_vertical" android:textcolor="@color/colortext" android:textsize="20sp" /> </linearlayout> </relativelayout>
----------------------animation xml file----------------------
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fromydelta="0%" android:interpolator="@android:anim/decelerate_interpolator" android:toydelta="-100%" /></set>
-----------java file in apply animation on click event---------
public void onclick(view v) { switch (v.getid()) { case r.id.my_pofile: animate= animationutils.loadanimation(ctx,r.anim.animone); subprofile.setvisibility(view.visible); subprofile.startanimation(animate); break; //other cases }}
try this:
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fromydelta="0%" android:interpolator="@android:anim/decelerate_interpolator" android:toydelta="-100%" />
Comments
Post a Comment