動畫這一知識點算是水比較深了,主要在自定義動畫中可是大有文章,并且技術都會了后就需要看設計能力了。
當然這些不是筆者博客的重點,筆者還是基本只講技術上的,本篇博客就講一講簡單的**設置Activity的跳轉動畫**。(其實就是調用一些系統內置的動畫,暫時不涉及自己寫動畫。)
效果:(代碼其實很簡單,就不**上傳**源碼了。)

**可能碰到的問題:**
在輸入“R.anim.”之后沒有自動提示,Control+鼠標左擊“R.anim”,然后可以看到系統內置的一些動畫,直接復制黏貼即可。如下圖:

系統內置動畫:(其他的一些讀者可以自己試試看)

(有好奇的讀者可能希望自己也寫一個動畫,在下一篇博客,筆者會專門寫。)
代碼如下:**(android版本需要在3.0以上)**
MainActivity:
~~~
package com.example.animationchanges;
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button=(Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,OneActivity.class);
startActivity(intent);
//設置跳轉動畫
overridePendingTransition(R.anim.abc_slide_in_bottom,R.anim.abc_slide_out_bottom);
}
});
}
}
~~~
OneActivity:
~~~
package com.example.animationchanges;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class OneActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_one);
}
}
~~~
activity_main:
~~~
<?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"
android:background="#a31212"
>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="界面切換"/>
</RelativeLayout>
~~~
activity_one:
~~~
<?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"
android:background="#1f9c16"
>
</RelativeLayout>
~~~
- 前言
- android Nine-Patch的使用(制作聊天界面必學)
- android 圖片文字輪播效果(圖片和文字自動滾動)
- LinearLayout布局中如何讓控件置底
- viewpager+將activity轉化成view 做主界面(可點擊可滑動,超容易理解的demo)
- android swipeRefreshLayout 下拉刷新 google官方組件
- android 自定義AlertDialog 與Activity相互傳遞數據
- android 簡單地設置Activity界面的跳轉動畫
- android XML動畫初步解析(activity界面之間跳轉demo)
- android selector設置button點擊效果(詳細)以及常見問題
- android 用java動態設置布局(增添刪除修改布局)