首页 > 其他 > 详细

ViewPager学习感受-思路

时间:2015-01-03 18:29:51      阅读:236      评论:0      收藏:0      [点我收藏+]

ViewPager 是一个容器,定义在一个Layout里面,但是要注意定义的时候要写明包名:

guide.xml文件
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.view.ViewPager android:id="@+id/guideViewPager" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#000" > </android.support.v4.view.ViewPager> </RelativeLayout>

 

ViewPager里面的东西是另外的几个Layout:

guide_page_1.xml文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/guide1"/> </LinearLayout>

 

用inflater的方式把这些 guide_page_1.xml、guide_page_2.xml等文件变成一个view对象,并且放到一个List里面:

//inflater是把Layout文件变成View对象的一个家伙
LayoutInflater inflater = LayoutInflater.from(this);
views = new ArrayList<View>();
views.add(inflater.inflate(R.layout.guide_page_1,null));
views.add(inflater.inflate(R.layout.guide_page_2,null));
views.add(inflater.inflate(R.layout.guide_page_3,null));
views.add(inflater.inflate(R.layout.guide_page_4,null));
views.add(inflater.inflate(R.layout.guide_page_5,null));    

 

把做好的,里面装满View对象的(其实就是那些Layout)List发送给PageAdapter,让Adapter自己往里生成就可以了。

关于Adapter的内部我琢磨琢磨再记录。

 

ViewPager学习感受-思路

原文:http://www.cnblogs.com/wangji/p/4199749.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!