最近在用ViewPager做引导界面,并解决了ViewPager向右滑动到最后,再向右滑动无法实现界面跳转的问题。先上效果图:
样例代码:
public class Guide extends Activity implements OnClickListener,
OnPageChangeListener ,OnTouchListener{
private ViewPager viewPager;
private ViewPagerAdapter viewPagerAdapter;
private List views;
private ImageView[] dots;
private int currentIndex;
private int lastX = 0;
private static final int[] pics = {R.drawable.g2, R.drawable.g3, R.drawable.g4 };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_guide);
views = new ArrayList();
LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.FILL_PARENT);
for (int i = 0; i < pics.length; i++) {
ImageView iv = new ImageView(this);
iv.setLayoutParams(mParams);
iv.setImageResource(pics[i]);
views.add(iv);
}
viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPagerAdapter = new ViewPagerAdapter(views);
viewPager.setOnTouchListener(this);
viewPager.setAdapter(viewPagerAdapter);
viewPager.setOnPageChangeListener(this);
}
完整代码下载:http://www.drovik.com/android/demo/ViewPaperTest.rar
如有疑问,欢迎留言讨论!
- 相关文章
- Android中 BuildConfig.java的讨论 (1795人浏览)
- android资源动态合并:Immutable bitmap passed to (634人浏览)
- android开发环境之ADT安装,卸载,更新 (184人浏览)
- 在Ubuntu中用Android NDK编译FFmpeg (2216人浏览)
- Android 3D倒影相册开发 (1698人浏览)
- Android Tombstone/Crash的log分析和定位 (708人浏览)
- android - UI设计之shape和selector的结合使用 (464人浏览)
[博主回复] 谢谢!
[博主回复] 非常高兴,能帮上忙! 哈哈~
[博主回复] 谢谢!