Moving An Image Through A Linearlayout
Solution 1:
Please take a look at the Animation class, specifically the Tween Animation, more specifically the Translate element. Create an animation file in your project then apply this animation to your image. For example, this animation would move an object from the center of the screen to the right side.
<?xml version="1.0" encoding="utf-8"?><translatexmlns:android="http://schemas.android.com/apk/res/android"android:toXDelta="100%p"android:fromXDelta="0%"android:duration="300"android:fillEnabled="true"android:fillAfter="true"></translate>
EDIT: To apply this animation to a Button, a TextView, an ImageView, etc.
ImageViewimageView= (ImageView) findViewById(R.id.myImageView);
AnimationexitAnimation= AnimationUtils.loadAnimation(this, R.anim.exit_animation);
imageView.startAnimation(exitAnimation);
Solution 2:
you have to use Translate Animation. For example, this animation would move an image from Left side of the screen to the right side of the screen.
The AnimationActivity is
listener = newAnimationListener() {
@OverridepublicvoidonAnimationStart(Animation animation) {}
@OverridepublicvoidonAnimationRepeat(Animation animation) {}
@OverridepublicvoidonAnimationEnd(Animation animation) {
System.out.println("End Animation!");
//load_animations();
}
};
}
@OverridepublicvoidonClick(View v) {
// TODO Auto-generated method stubif (v==button)
{
moveLefttoRight = newTranslateAnimation(0, 200, 0, 0);
moveLefttoRight.setDuration(1000);
moveLefttoRight.setFillAfter(true);
my_image.startAnimation(moveLefttoRight);
}
}
}
xml code is
<LinearLayout 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=".MainActivity" >
<ImageView
android:id="@+id/diceid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/dice"/>
</LinearLayout>
and anim file is
<?xml version="1.0" encoding="utf-8"?><rotatexmlns:android="http://schemas.android.com/apk/res/android"android:fromDegrees="0"android:toDegrees="360"android:pivotX="50%"android:pivotY="50%"android:duration="2000"android:repeatMode="reverse"android:repeatCount="infinite"android:startOffset="0"
/>
may be this is the answer what you are searching.
Solution 3:
I would check your source again. Maybe it's out of context. But the easiest way to do this is to use a Translate animation that originates from the Image's starting place and translates it to the other side of the screen. After that is done I usually register an animation callback so that I can update the true position of the image after the animation is over. hope that helps.
Solution 4:
Or is it the Gallery that you are looking for?
Post a Comment for "Moving An Image Through A Linearlayout"