0

我是安卓新手。我想在 android 中为启动画面设置动画。任何链接或示例代码都将被接受。

public class OneActivity extends Activity
{
    @Override
    protected void onCreate( Bundle savedInstanceState )
    {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.one );
        ((Button)findViewById( R.id.next_button )).setOnClickListener( new OnClickListener()
        {
            @Override
            public void onClick( View v )
            {
                startActivity( new Intent( OneActivity.this, TwoActivity.class ) );
                overridePendingTransition( R.anim.slide_in_left, R.anim.slide_out_left );
            }
        });
    }
}

slide_in_left.xml:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="100%p" android:toXDelta="0%p"
    android:duration="@android:integer/config_longAnimTime"/>

slide_out_left.xml :

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0" android:toXDelta="-100%p"
    android:duration="@android:integer/config_longAnimTime" />

有没有其他办法然后这个..??或者不使用 XML ..!谢谢你。

4

1 回答 1

0

slape.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- <scale
        android:duration="2000"
        android:fillBefore="false"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:toXScale="1.0"
        android:toYScale="1.0" />

    <translate
        android:duration="2000"
        android:fromXDelta="-200"
        android:fromYDelta="-200" /> -->
        <scale android:fromXScale="1"
        android:fromYScale="1"
        android:toXScale="1.0"
        android:toYScale="1.0"
        android:duration="1000"/>
    <translate
        android:fromXDelta="200"
        android:fromYDelta="200"
        android:toXDelta="0"
        android:toYDelta="0"
        android:duration="1000"/>

</set>

在活动中:

ImageView imgMain = (ImageView) findViewById(R.id.imgMain);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.slape);
        imgMain.startAnimation(animation);

new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                    runOnUiThread(new Runnable() {
                     public void run() {

                     }
                });
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }).start();
于 2013-06-11T12:16:19.857 回答