Wednesday, 15 July 2015

Image not moving to the bottom of screen during animation in android -



Image not moving to the bottom of screen during animation in android -

i new android. doing project in want move image top bottom of screen. have written code image moves upto middle of screen , returns top of screen without reaching downwards bottom...

this mainacticity.java file

setcontentview(r.layout.activity_eg_main); imageview image = (imageview) findviewbyid(r.id.image1); image.setimageresource(r.drawable.ic_launcher); animation animation = animationutils.loadanimation(this, r.anim.testing); image.startanimation(animation);

this res/layout/activity_eg_main.xml

<relativelayout 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" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.example.example.egmainactivity" > <imageview android:id="@+id/image1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentdescription="@string/hehe" android:layout_alignparenttop="true" /> </relativelayout>

this res/anim/testing.xml file

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromydelta="0" android:toydelta="100" android:duration="1000"> </translate> </set>

please suggest corrections possible... in advance.....

<translate android:fromydelta="0%" android:toydelta="100%" android:duration="1000"> </translate>

else follow approach

make folder anim in res folder of project. add together slide_up.xml slide_up animation. add together slide_down.xml slide downwards animation.

code slide_down.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromxdelta="0" android:fromydelta="-1000" android:duration="1500"/> </set>

code slide_up.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromxdelta="0" android:fromydelta="1000" android:duration="1500"/> </set>

to start attach object want animated:

animation slideup = animationutils.loadanimation(getapplicationcontext(), r.anim.slide_up); imageview img = (imageview) findviewbyid(r.id.imgv); img.startanimation(slideup);

android

No comments:

Post a Comment