控件属性设置:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <ViewFlipper android:id="@+id/viewFlipper1" android:layout_width="match_parent" android:layout_height="match_parent" android:flipInterval="3000" android:inAnimation="@anim/push_down_in_no_alpha" android:outAnimation="@anim/push_down_in_no_alpha" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" > <ImageView android:id="@+id/p_w_picpathView1" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY" android:src="@drawable/photo1" /> <ImageView android:id="@+id/p_w_picpathView2" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY" android:src="@drawable/photo2" /> <ImageView android:id="@+id/p_w_picpathView3" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY" android:src="@drawable/photo3" /> </ViewFlipper> </RelativeLayout>
启动ViewFlipper:
public class MainActivity extends Activity { /* * ViewFlipper幻灯片主要属性: * android:flipInterval="3000" 延迟时间 * android:inAnimation="@android:anim/slide_in_left" 进入动画 * android:outAnimation="@android:anim/slide_out_right" 退出动画 */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ViewFlipper viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper1); viewFlipper.startFlipping(); } }