ViewSwitcher使用範例

1、簡介java


    ViewSwitcher適用於兩個視圖帶動畫效果的切換。這裏實現兩個視圖切換的功能,並附帶滑屏效果。android

 

  2、截圖app

2、範例代碼ide


    帶動畫效果的切換視圖一和視圖二。 測試

    xml動畫

<ViewSwitcher android:layout_alignParentBottom="true"
android:persistentDrawingCache="animation" android:id="@+id/bottom"
android:layout_width="match_parent" android:inAnimation="@android:anim/slide_in_left"
android:outAnimation="@android:anim/slide_out_right" android:layout_height="122.0dip">
<RelativeLayout android:layout_width="fill_parent"
android:layout_gravity="bottom" android:layout_marginBottom="12.0dip"
android:id="@+id/lyBottom" android:layout_height="wrap_content">
<Button android:id="@+id/btn_pre" android:text="上一步"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_toLeftOf="@+id/btn_middle"
android:layout_marginRight="150.0dip" />
<Button android:id="@+id/btn_middle" android:layout_width="wrap_content"
android:layout_centerInParent="true" android:onClick="onClick" android:visibility="invisible"
android:textSize="22.0sp"
android:layout_height="wrap_content"></Button>
<Button android:id="@+id/btn_next" android:text="下一步"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_toRightOf="@+id/btn_middle"
android:layout_marginLeft="150.0dip" />
</RelativeLayout>
<RelativeLayout android:layout_width="fill_parent"
android:layout_gravity="bottom" android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:src="@drawable/cube" android:id="@+id/btn_reinsure"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="150.0dip"></ImageView>
<ImageView android:src="@drawable/cyddz" android:id="@+id/btn_identity"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btn_reinsure"
android:layout_marginLeft="124.0dip"></ImageView>
<ImageView android:src="@drawable/cykvmce" android:id="@+id/btn_insure_query"
android:layout_toRightOf="@+id/btn_identity" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginLeft="140.0dip"></ImageView>
<ImageView android:src="@drawable/m8gprs" android:id="@+id/btn_review"
android:layout_toRightOf="@+id/btn_insure_query"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="140.0dip"></ImageView>
<ImageView android:src="@drawable/th_appshareth"
android:layout_toRightOf="@+id/btn_review"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="130.0dip"></ImageView>
</RelativeLayout>
</ViewSwitcher>xml


代碼說明:圖片

        1. 這裏使用系統自帶的切換效果@android:anim/slide_in_left和@android:anim/slide_out_right。ip

        2. 請你們自行準備測試圖片 animation

    java bottom = (ViewSwitcher) findViewById(R.id.bottom); //切換爲第一個 bottom.setDisplayedChild(0); //切換到下一個 //bottom.showNext()

相關文章
相關標籤/搜索