Android開發中activity切換動畫的實現,androidactivity

來源:互聯網
上載者:User

Android開發中activity切換動畫的實現,androidactivity

 

(1)我們在MainAcitvity中定義兩個textview,用於點擊觸發切換Activity事件,下面是布局檔案代碼。

  <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:background="@drawable/top_bg"            android:orientation="horizontal" >            <LinearLayout                android:id="@+id/list_all"                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_weight="1.0"                android:background="@drawable/btn_bottom_bg"                android:clickable="true"                android:gravity="center"                android:orientation="vertical" >                <TextView                    android:id="@+id/tv_all"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:drawableLeft="@drawable/city"                    android:drawablePadding="5.0dip"                    android:duplicateParentState="true"                    android:gravity="center"                    android:text="@string/all"                    android:textColor="@color/white"                    android:textSize="13.5sp" />            </LinearLayout>            <LinearLayout                android:id="@+id/list_school"                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_weight="1.0"                android:background="@drawable/btn_bottom_bg"                android:clickable="true"                android:gravity="center"                android:orientation="vertical" >                <TextView                    android:id="@+id/tv_school"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:drawableLeft="@drawable/location"                    android:drawablePadding="5.0dip"                    android:duplicateParentState="true"                    android:gravity="center"                    android:text="@string/school"                    android:textColor="@color/white"                    android:textSize="13.5sp" />            </LinearLayout>        </LinearLayout>

(2)為textView添加點擊事件。重寫overridePendingTransition方法,添加切換動畫的效果,第一個參數是進入的效果,第二個參數是退出的效果。

TextView tv_all = (TextView) this.findViewById(R.id.tv_all);        tv_all.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View v) {                Intent intent = new Intent();                intent.setClass(SecondActivity.this, MainActivity.class);                startActivity(intent);                overridePendingTransition(R.anim.slide_in_left,                          R.anim.slide_out_right);             }        });

(3)slide_in_left.xml進入的效果

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >      <translate          android:duration="500"          android:fromXDelta="-50%p"          android:toXDelta="0" />      <alpha          android:duration="500"          android:fromAlpha="0.0"          android:toAlpha="1.0" />  </set>  

()slide_out_right.xml退出的效果

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <translate         android:duration="500"         android:fromXDelta="0"         android:toXDelta="50%p" />    <alpha         android:duration="500"         android:fromAlpha="1.0"         android:toAlpha="0.0" />  </set>  

 


安卓開發,在同一個activity中, 切換兩種布局layout時,可以實現動畫效果,範例代

切換兩種布局,怎麼個切換法
 
安卓開發 怎實現activity的左右切換?

你改成三個view,放在一個ViewPager裡,只用一個Activity就行了,用TabHost也可以,不過這個已經過時了。。。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.