设置TabLayout框架和侧拉,注意必须导 design包
来源:互联网 发布:在淘宝刷好评犯法吗 编辑:程序博客网 时间:2024/06/05 04:21
/////////////////////////////////////主方法
private DrawerLayout drawerLayout; private ListView lv;private TabLayout mtabLayout; private ViewPager mviewPager; private LayoutInflater minflater; //设置条目名字 private String[] channels={"关注","推荐","热点","佛山","视频","社会","图片","娱乐"}; //设置URL地址 private String urlS="https://api.tianapi.com/wxnew/?key=8d6e3228d25298f13af4fc40ce6c9679&num="; //创建标题集合private List<String> mTitleList =new ArrayList<>(); //创建页卡视图集合private List<fm01> mViewList=new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_succ); //侧拉 initt(); mviewPager= (ViewPager) findViewById(R.id.vp_view); mtabLayout= (TabLayout) findViewById(R.id.tabs); minflater=LayoutInflater.from(this); for (int i=0;i<channels.length;i++){fm01 fragment = new fm01(); Bundle b=new Bundle(); b.putString("name",channels[i]); b.putString("url",urlS+i); fragment.setArguments(b); //收集fragment mViewList.add(fragment); //给tabLayout添加tab选项卡 mtabLayout.addTab(mtabLayout.newTab().setText(channels[i])); } FragmentManager fm=getSupportFragmentManager(); //给mviewpager设置适配器 MyFragmentadap myFragmentadap = new MyFragmentadap(fm, mViewList); mviewPager.setAdapter(myFragmentadap); mtabLayout.setupWithViewPager(mviewPager);//将TabLayout和ViewPager关联起来 mtabLayout.setTabsFromPagerAdapter(myFragmentadap);//给tabs设置适配器 }
//适配器 class MyFragmentadap extends FragmentPagerAdapter{ private List<fm01> mViewList; public MyFragmentadap(FragmentManager fm, List<fm01> mViewList) { super(fm); this.mViewList = mViewList; } public Fragment getItem(int position) { return mViewList.get(position); } public int getCount() { return mViewList.size(); } @Override public CharSequence getPageTitle(int position) { return channels[position]; } }
//侧拉 public void initt(){ drawerLayout= (DrawerLayout) findViewById(R.id.adr); lv= (ListView) findViewById(R.id.lv); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { drawerLayout.closeDrawer(lv); } }); }////////////////////////////////////////////////////////////////////////主界面里的XML
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/adr" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.yuekaochongci01.Succ"><ListView android:id="@+id/lv" android:layout_width="254dp" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:divider="#FF7F50" android:dividerHeight="1dp" android:background="#D3D3D3" android:entries="@array/books" ></ListView><LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabIndicatorColor="@color/red" app:tabMode="scrollable" app:tabSelectedTextColor="@color/red" app:tabTextColor="@color/black"/> <android.support.v4.view.ViewPager android:id="@+id/vp_view" android:layout_width="match_parent" android:layout_height="wrap_content"/></LinearLayout></android.support.v4.widget.DrawerLayout>
阅读全文
0 0
- 设置TabLayout框架和侧拉,注意必须导 design包
- DrawerLayout侧拉+TabLayout
- design包中的tablayout的使用
- TabLayout滑动和viewPager的联动+drawerLayout的侧拉
- Material Design之CollapsingToolbarLayout 和 TabLayout使用
- Android L、M扩展支持包design中widget:TabLayout
- 关于Design包中TabLayout+ViewPager的简单使用
- Android design包自定义tablayout的底部导航栏
- android 自带的design包中tablayout使用
- android.support.design.widget.TabLayout设置指示器的宽度
- 侧拉+TabLayout+轮播+XListView
- Android Material Design TabLayout属性app:tabMode和app: tabGravity
- Android Material Design TabLayout属性app:tabMode和app: tabGravity
- TabLayout+Fragment android design
- android support design tablayout
- Material Design -- TabLayout
- Material Design之TabLayout
- 使用design.widget.TabLayout
- socket阻塞与非阻塞,同步与异步
- 【转载】Bash 脚本进阶,经典用法及其案例
- SQL查询的艺术学习笔记--数据插入操作
- LeetCode-78. Subsets
- 码率、分辨率、帧率
- 设置TabLayout框架和侧拉,注意必须导 design包
- 将word文档转换为html、PDF等
- IO
- node部署到linux服务器
- windows下vim中文乱码的解决方法
- Effective Java(什么是clone、什么是“深拷贝”和“浅拷贝”)
- DAO层
- Android JNI开发(4)--访问Java的实例变量和静态变量
- HDU 1815 Building roads(二分+2-SAT)