问题描述
|
我想了解图像翻译活动。
布局应包含两个图像,并且这两个图像应
单击按钮时,同时向左和向右拆分
一个图像应向左平移,另一图像应向右平移。
感谢帮助。
解决方法
邮编或查看有关您所要求内容的文档,并获得更多描述性信息。这不是自动售货机,人们通常不想仅仅因为有人要求而为人们编码。究竟有什么问题是一个好的开始?请阅读文档,然后重试,如果无法获取,请返回详细信息;您会更快地找到帮助。
[edit] ----下面的教程-----
由于您实际上已经在此处提供了一定程度的详细信息,因此我想向您展示一个简单的方法。首先,
this
是动画信息的好地方。用它。其次,此代码在Droid2上对我来说非常完美。
public class animationTEST extends Activity implements AnimationListener {
LinearLayout layout;
LinearLayout layout2;
Animation movement;
Animation movement2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get the layouts
layout = (LinearLayout) findViewById(R.id.linearLayout1);
layout2 = (LinearLayout) findViewById(R.id.linearLayout2);
// Create animation for right image
movement = AnimationUtils.loadAnimation(this,R.layout.animation_test);
movement.reset();
movement.setAnimationListener(this);
// Create animation for left image
movement2 = AnimationUtils.loadAnimation(this,R.layout.animation_test2);
movement2.reset();
movement2.setAnimationListener(this);
// Start animation on each image
layout2.startAnimation(movement2);
layout.startAnimation(movement);}
// Listen for animations to be finished
// There are more efficient ways,I\'m just being lazy.
public void onAnimationEnd(Animation animation) {
layout.setVisibility(View.INVISIBLE);
layout2.setVisibility(View.INVISIBLE);
// or do whatever it is you wanted to do here,like launch another activity?
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
}
main.xml
文件:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:orientation=\"vertical\" android:layout_width=\"fill_parent\"
android:layout_height=\"fill_parent\">
<TextView android:layout_width=\"fill_parent\"
android:layout_height=\"wrap_content\" android:text=\"Animation Test Activity\" />
<RelativeLayout android:layout_width=\"match_parent\"
android:layout_height=\"match_parent\" android:id=\"@+id/relativeLayout1\">
<LinearLayout android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\" android:layout_centerVertical=\"true\"
android:layout_marginLeft=\"105dip\" android:id=\"@+id/linearLayout2\">
<ImageView android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\" android:src=\"@drawable/icon\"
android:layout_marginRight=\"30dip\" android:id=\"@+id/imageView2\"></ImageView>
</LinearLayout>
<LinearLayout android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\" android:layout_centerVertical=\"true\"
android:id=\"@+id/linearLayout1\" android:layout_marginLeft=\"145dip\">
<ImageView android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\" android:src=\"@drawable/icon\"
android:layout_marginRight=\"30dip\" android:id=\"@+id/imageView1\"></ImageView>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
animation_test.xml
(定义翻译动画)
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<translate xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:fromXDelta=\"0\"
android:toXDelta=\"65%p\"
android:fromYDelta=\"0\"
android:toYDelta=\"0%\"
android:duration=\"3000\"
android:zAdjustment=\"top\"/>
animation_test2.xml
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<translate xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:fromXDelta=\"0\"
android:toXDelta=\"-65%p\"
android:fromYDelta=\"0\"
android:toYDelta=\"0%\"
android:duration=\"3000\"
android:zAdjustment=\"top\"/>
如果您听不懂,请返回阅读我给您的两个文档。这里有足够的信息来了解任何动画。但是,您想使用“ 8”个对象是不对的,因为这是帧动画,而不是变换或运动。基于帧的动画只是使某些东西看起来像是跳舞或挥舞。当您尝试简单地移动,淡入淡出或缩放图像时,需要转换动画。希望这可以帮助!