Android 图片闪烁(延迟切换)

时间:2021-12-03 21:49:25
 <LinearLayout 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"
android:orientation="vertical" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> <ViewFlipper
android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:flipInterval="200" > <TextView
android:id="@+id/text_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text_1" /> <TextView
android:id="@+id/text_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text_12" /> <TextView
android:id="@+id/text_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text_13" /> <TextView
android:id="@+id/text_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="text_14" />
</ViewFlipper> <Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="stop" /> </LinearLayout>
 package com.example.demoviewfliper;

 import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ViewFlipper; public class MainActivity extends Activity {
ViewFlipper mVf;
Button btn; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); mVf = (ViewFlipper) findViewById(R.id.flipper);
mVf.startFlipping(); btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
if (mVf != null && mVf.isFlipping()) {
mVf.stopFlipping();
mVf.setDisplayedChild(mVf.getChildCount() - 1);
} }
});
} }