安卓图像翻译

时间:2011-04-13 05:45:09

标签: android layout

我想知道图片翻译活动。

布局应包含两个图像,这两个图像应该是 当我们点击按钮时,同时向左和向右分开 一张图像应向左转,另一张向右转。

非常感谢帮助。

1 个答案:

答案 0 :(得分:0)

发布代码或查看documentation关于您所询问的内容并获得更具描述性的内容。这不是代码的自动售货机,人们通常不希望只为人们编码,因为他们要求它。你究竟遇到什么问题将是一个良好的开端?请阅读文件,再试一次,如果你不能得到它的详细信息;你会更快找到帮助。

[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"/>

如果您无法理解这一点,请返回并阅读我给您的两份文件。这里有足够的信息来了解任何动画。但是,您想要使用animationDrawable个对象是不对的,因为这是一个帧动画,而不是转换或动作。基于帧的动画只是让它看起来像跳舞或挥舞着。当您尝试简单地移动,淡化或缩放图像时,您需要转换动画。希望这可以帮助!

相关问题