[英]How to Animate two image view from Center to opposite to each other?
i want to animate the two images from middle of the screen to opposite to each other. 我想使两个图像从屏幕中间到彼此相对。 like below image. 如下图所示。
whatever i have done so far is right now i am able animate only one image from left to right and vice versa but now i want to animate them from middle. 到目前为止,我到目前为止所做的一切都只能使一个图像从左到右进行动画处理,反之亦然,但是现在我希望从中间对它们进行动画处理。
here is my code : 这是我的代码:
b1 = (Button) findViewById(R.id.button1);
logo = (ImageView) findViewById(R.id.imageView1);
Display display = getWindowManager().getDefaultDisplay();
width = display.getWidth();
final Animation posX = new TranslateAnimation(0, width - 50, 0, 0);
posX.setDuration(1500);
posX.setFillAfter(true);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
logo.startAnimation(posX);
logo.setVisibility(View.VISIBLE);
}
});
Edit: 编辑:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:background="@drawable/set_user_profile_back"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="50dp"
android:contentDescription="@string/hello_world"
android:src="@drawable/prev_btn" />
<ImageView
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView1"
android:contentDescription="@string/hello_world"
android:src="@drawable/next_btn" />
</RelativeLayout>
Thanks 谢谢
ImageView img1 = findViewById(R.id.img1);
ImageView img2 = findViewById(R.id.img2);
Animation img1_Anim = AnimationUtils.loadAnimation(this,
R.anim.img1_animation);
img1_Anim.setAnimationListener(AnimationListener);
img1.startAnimation(img1_Anim);
Animation img2_Anim = AnimationUtils.loadAnimation(this,
R.anim.img2_animation);
img2_Anim.setAnimationListener(AnimationListener);
img2.startAnimation(img2_Anim);
private AnimationListener AnimationListener = new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
};
img1_animation img1_animation
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<translate
android:duration="500"
android:fromXDelta="50%"
android:toXDelta="0%" />
</set>
img2_animation img2_animation
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<translate
android:duration="500"
android:fromXDelta="50%"
android:toXDelta="100%" />
</set>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.