1. 程式人生 > >屬性動畫,跳轉到頁面

屬性動畫,跳轉到頁面

——————首先用shap畫出小球,特別簡單

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners
        android:radius="50dp"
        />
    <stroke
        android:color="#a44848"
        android:width="1dp"
        />
    <solid
        android:color="#a44848"
        />
</shape>

——————然後就是佈局的程式碼,沒有什麼奇特的東西

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <TextView
        android:id="@+id/text_view"
        android:layout_width="50dp"
        android:background="@drawable/bg_circle"
        android:layout_height="50dp" />
</RelativeLayout>

——————當然最後就是我們的主頁面了

public class WelcomeActivity extends AppCompatActivity {

    private TextView txtCircle;
    public static final int FLAG = 1;
    private Handler handler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what ==FLAG) {
                Intent intent=new Intent(WelcomeActivity.this,MainActivity.class);
                startActivity(intent);
                finish();
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        txtCircle = findViewById(R.id.text_view);
        handler.sendEmptyMessageDelayed(FLAG,6000);
//這個是你的模擬器的解析度,是多少,大的那個就是長,小的就是寬
        ObjectAnimator tyAnimator = ObjectAnimator.ofFloat(txtCircle, "translationY", 0, 1920);
        ObjectAnimator txAnimator = ObjectAnimator.ofFloat(txtCircle, "translationX", 0, 1080);
        txAnimator.setDuration(5000);
        txAnimator.start();
        tyAnimator.setDuration(5000);
        tyAnimator.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }
}