你可以试试Horizontal View Swiping with ViewPager
,或者ViewFlipper
我在下面添加了两个链接。
ViewPagers 从 PagerAdapters 获取他们的视图,这使您可以完全控制视图的重用和回收。提供了一个称为 FragmentPagerAdapter 的 PagerAdapter 实现,以方便在 ViewPager 中使用 Fragments;
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
… />
支持演示:
public static class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return NUM_ITEMS;
}
@Override
public Fragment getItem(int position) {
return ArrayListFragment.newInstance(position);
}
}
当您在列表中滑动时,FragmentPagerAdapter 将分离每个片段,但将它们保存在内存中,以便在用户向后滑动时可以简单地重新连接它们。
有关更多信息,请尝试此链接
或者你可以去ViewFlipper
public class ViewFlipperActivity extends Activity implements OnGestureListener,
OnTouchListener {
private ViewFlipper mViewFlipper;
private GestureDetector mGestureDetector;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.viewflipper_layout);
mGestureDetector = new GestureDetector(this);
mViewFlipper = (ViewFlipper) findViewById(R.id.viewflipper);
mViewFlipper.setOnTouchListener(this);
mViewFlipper.startFlipping();
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
if (e2.getX() - e1.getX() > 0) {
//mViewFlipper.showPrevious();
} else {
//mViewFlipper.showNext();
}
return true;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
mGestureDetector.onTouchEvent(event);
return true;
}
}
ViewFilpper 控件系统自带控件之一,主开关和设置在同屏动画,和自动播放,用法同上,所以这个例子就是你所需要的!!!