• Android ViewPager


    将layout布局转换为view对象。
         1>layoutInflater lf=getLayoutInflater().from(this);
             lf.inflate(resource,root);
         2>View.inflate(context,resource,root);
     
    配置adapter
         1>pageradapter   数据源:list<View>
         2>FragmentPagerAdapter      数据源:list<Fragment>
         3>FragmentStatePagerAdapter     数据源:list<Fragment>
     
    android.support.v4.view.ViewPager
              android.support.v4.view.pagerTabStrip
              android.support.v4.view.pagerTitleStrip
     
     <android.support.v4.view.ViewPager
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/pager"
            >
            <android.support.v4.view.pagerTabStrip
                android:layout_width= "wrap_content"
                   android:layout_height="wrap_content"
                   android:id="@+id/tab"
                >
            </android.support.v4.view.pagerTabStrip>
            <android.support.v4.view.pagerTitleStrip
                android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:id="@+id/title"
                >
            </android.support.v4.view.pagerTitleStrip>
        </android.support.v4.view.ViewPager >
       
     
     
    public class MyPagerAdapet extends PagerAdapter{
     
           
            private List<View> viewlist ;
            private List<String> tablist ;
           
            public MyPagerAdapet(List<View> viewlistList ,List<String> tablist){
                   this.viewlist =viewlistList ;
                   this.tablist =tablist;
           }
           
            /**
            * 返回页卡的数量
            */
            @Override
            public int getCount() {
     
                   return viewlist .size();
           }
     
           
            /**
            *判断当前的view是否来自于对象  arg0==arg1
            */
            @Override
            public boolean isViewFromObject(View arg0, Object arg1) {
                   return arg0==arg1;
           }
           
            /**
            * 实例化一个页卡
            */
            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                  container.addView( viewlist.get(position));
                   return viewlist .get(position);
           }
     
            /**
            * 销毁一个页卡
            */
            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                  container.removeView( viewlist.get(position));
           }
           
            /**
            * 设置 viewpage页卡的标题
            */
            @Override
            public CharSequence getPageTitle(int position) {
                   // TODO Auto-generated method stub
                   return tablist .get(position);
           }
    }
     
    public class MainActivity extends ActionBarActivity {
     
            private List<View> viewlist ;
            private ViewPager pager ;
            private PagerTabStrip tab;
            private List<String> tablist ;
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                   super.onCreate(savedInstanceState);
                  setContentView(R.layout. activity_main);
                   viewlist= new ArrayList<View>();
                   /**
                   * 通过view对象作为view怕给的数据源
                   */
                  View view1=View. inflate(this, R.layout. view1, null );
     
           
                   viewlist.add(view1);
     
                   //初始化pager
                   pager=(ViewPager) findViewById(R.id. pager);
                   //创建pagerAdapter适配器
                  MyPagerAdapet adapet= new MyPagerAdapet(viewlist ,tablist );
                   //viewpager 加载适配器
                   pager.setAdapter(adapet);
           }
    }
     
     
     
    FragmentPagerAdapter
    使用fragment作为viewpager的数据源。
    stareblankly.cn
  • 相关阅读:
    数据采集都做不到,怎么谈智能制造?
    值得借鉴的德国制造工厂生产观念!
    APS应用案例|纽威阀门实现高效排产
    MES应用案例|新宏泰电器乘上智能制造的东风
    你的MES今天升级了吗?
    APP-2.1-Hbuilder与夜神 & HbuilderX与夜神模拟器连接
    APP-3-百度地图应用
    APP-2-Hbuilder开发环境搭建
    ABAP-Keyword Documentation
    APP-1-相关介绍及资料
  • 原文地址:https://www.cnblogs.com/stareblankly/p/4844222.html
Copyright © 2020-2023  润新知