ViewPager-思路-草稿

来源:互联网 发布:win7网络不被发现 编辑:程序博客网 时间:2024/05/08 10:27
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的内部我琢磨琢磨再记录。

0 0
原创粉丝点击