案例中有"上一个""下一个""自动播放",但是我觉得可以更加完善一下,点击自动播放,按钮变成"停止播放",在按"停止播放"变为"自动播放",同样的排除在自动播放时,按下"上一个"和"下一个"均变为 "自动播放"
MainActivity.java
-
public class MainActivity extends Activity -
-
int[] imageIds = new int[] -
-
R.drawable.shuangzi, R.drawable.shuangyu, -
R.drawable.chunv, R.drawable.tiancheng, R.drawable.tianxie, -
R.drawable.sheshou, R.drawable.juxie, R.drawable.shuiping, R.drawable.shizi, R.drawable.baiyang, R.drawable.jinniu, -
-
private AdapterViewFlipper flipper; -
private Button button_auto; -
-
public void onCreate(Bundle savedInstanceState) -
-
super.onCreate(savedInstanceState); -
setContentView(R.layout.main); -
flipper = (AdapterViewFlipper) findViewById(R.id.flipper); -
button_auto = (Button) findViewById(R.id.button_auto); -
// 创建一个BaseAdapter对象,该对象负责提供Gallery所显示的列表项 -
BaseAdapter adapter = new BaseAdapter() -
-
-
-
-
-
-
-
public Object getItem(int position) -
-
-
-
-
public long getItemId(int position) -
-
-
-
-
-
public View getView(int position, View convertView, ViewGroup parent) -
-
-
ImageView imageView = new ImageView(MainActivity.this); -
imageView.setImageResource(imageIds[position]); -
-
imageView.setScaleType(ImageView.ScaleType.FIT_XY); -
-
imageView.setLayoutParams(new ViewGroup.LayoutParams( -
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); -
-
-
-
flipper.setAdapter(adapter); -
-
public void prev(View source) -
-
-
-
-
-
button_auto.setText("自动播放"); -
-
public void next(View source) -
-
-
-
-
-
button_auto.setText("自动播放"); -
-
public void auto(View source) -
-
String sting=button_auto.getText().toString(); -
-
-
-
button_auto.setText("停止播放"); -
-
-
button_auto.setText("自动播放"); -
-
-
|
XML文件
-
<?xml version="1.0" encoding="utf-8" ?> -
-
xmlns:android="http://schemas.android.com/apk/res/android" -
android:layout_width="match_parent" -
android:layout_height="match_parent"> -
-
android:id="@+id/flipper" -
android:layout_width="match_parent" -
android:layout_height="match_parent" -
android:flipInterval="2000" -
android:layout_alignParentTop="true"/> -
-
android:layout_width="wrap_content" -
android:layout_height="wrap_content" -
android:layout_alignParentBottom="true" -
android:layout_alignParentLeft="true" -
-
-
-
android:layout_width="wrap_content" -
android:layout_height="wrap_content" -
android:layout_alignParentBottom="true" -
android:layout_centerHorizontal="true" -
-
-
-
android:id="@+id/button_auto" -
android:layout_width="wrap_content" -
android:layout_height="wrap_content" -
android:layout_alignParentBottom="true" -
android:layout_alignParentRight="true" -
-
-
|
效果