新闻展示的view 库(tablayout+viewpager)
来源:互联网 发布:c语言论坛 编辑:程序博客网 时间:2024/05/21 22:58
https://github.com/xiuergit/EasyTabLayoutDemo.git
Easytablayout
一个简易的显示 新闻的库的UI组件,目前开发者只需要设置titles、与fragment就可以显示分页了,使用简单;
有三种样式可以设置,如下图;
效果图
使用方式
1、Easytablayout 的创建
支持两种方式
1)在布局文件里放置
<com.bigdata.easytablayout.View.EasyTabLayout android:id="@+id/easy" app:Style="@integer/Normal" android:layout_width="match_parent" android:layout_height="wrap_content"/>
2)在代码中创建
EasyTabLayout easyTabLayout=new EasyTabLayout(this);
2、设置显示的标题、与Fragment
public void setData(ArrayList<String> titles,ArrayList<Fragment> fragments); //例如 easyTabLayout.setData(DataToolTest.titles(),DataToolTest.fragments(DataToolTest.titles().size()));
3、设置样式
//方式1:在代码中 easyTabLayout.setStyle(EasyTabLayout.INDICATOR); //三种样式: public static int NORMAL=0; public static int INDICATOR=1; public static int LIGHT=2;// 方式2: app:Style="@integer/Normal"
4、Easytablayout 部分代码
package com.bigdata.easytablayout.View;import android.content.Context;import android.content.res.TypedArray;import android.graphics.Color;import android.os.Build;import android.support.annotation.Nullable;import android.support.design.widget.TabLayout;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentActivity;import android.support.v4.app.FragmentManager;import android.support.v4.view.ViewPager;import android.util.AttributeSet;import android.view.LayoutInflater;import android.widget.LinearLayout;import com.bigdata.easytablayout.Adapter.EasyViewpageAdapter;import com.bigdata.easytablayout.R;import java.util.ArrayList;/** * Created by xiuer on 17/5/26. * * @emil: 15536849144@163.com * @desc: */public class EasyTabLayout extends LinearLayout{ private String TAG="MarketView"; private ArrayList<String>titles; private TabLayout mTabLayout; private ViewPager mViewPager; private ArrayList<Fragment> fragments; private FragmentManager mFragmentManger; public static int NORMAL=0; public static int INDICATOR=1; public static int LIGHT=2; public void setData(ArrayList<String> titles,ArrayList<Fragment> fragments) { initView(titles,fragments); } private int mStyle; public EasyTabLayout(Context context) { this(context,null); } public EasyTabLayout(Context context, @Nullable AttributeSet attrs) { this(context,attrs,0); } public EasyTabLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray array=context.getTheme().obtainStyledAttributes(attrs, R.styleable.EasyTabLayout,defStyleAttr,0); LayoutInflater.from(context).inflate(R.layout.view_easytablayout, this, true); mTabLayout= (TabLayout) findViewById(R.id.easy_tab); mViewPager=(ViewPager)findViewById(R.id.easy_tab_viewPager); mFragmentManger= ((FragmentActivity)context).getSupportFragmentManager(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { mTabLayout.setLayoutMode(TabLayout.MODE_SCROLLABLE); } if(titles!=null&&fragments!=null){ initView(titles,fragments); } setStyle(array.getInteger(R.styleable.EasyTabLayout_Style,0)); } public void setStyle(int styleCode){ if(styleCode==NORMAL){ mTabLayout.setTabTextColors(Color.WHITE,Color.RED); mTabLayout.setSelectedTabIndicatorColor(Color.BLACK); mTabLayout.setBackgroundColor(Color.BLACK); } else if(styleCode==LIGHT) { mTabLayout.setTabTextColors(Color.BLACK,Color.RED); mTabLayout.setSelectedTabIndicatorColor(Color.WHITE); mTabLayout.setBackgroundColor(Color.WHITE); }else if(styleCode==INDICATOR){ mTabLayout.setTabTextColors(Color.BLACK,Color.RED); mTabLayout.setSelectedTabIndicatorColor(Color.RED); mTabLayout.setBackgroundColor(Color.WHITE); } } public void initView(ArrayList<String> titles,ArrayList<Fragment>fragments){ mViewPager.setAdapter(new EasyViewpageAdapter(mFragmentManger,fragments,titles)); mTabLayout.setupWithViewPager(mViewPager); }}
5、总结:目前这个组件,fragment 需要开发者自己定义,之后,我会定义出常见的1、2个模板,以及这个库的使用暂时不支持 gradle,需要module 依赖,后续,我会支持gradle;暂代更新,请看后续;
https://github.com/xiuergit/EasyTabLayoutDemo.git
阅读全文
0 0
- 新闻展示的view 库(tablayout+viewpager)
- 20ViewPager demo1,2:接收ViewPager展示View的使用
- TabLayout、ViewPager、FragmentPagerAdapter实现新闻导航栏
- Tablayout 底部导航的实现 (TabLayout 以及ViewPager联动)
- TabLayout 和ViewPager和Fragment的多页面滑动(主要实现一个水平的布局用来展示Tabs加上ViewPager实现联动效果)
- Tablayout+Viewpager的使用
- Tablayout Viewpager的实现
- TabLayout+ViewPager的使用
- TabLayout+ViewPager(1)
- drawerlayout+(viewpager+tablayout)
- 仿网易新闻主界面(二)——TabLayout+ViewPager
- TabLayout的简单使用(TabLayout+Fragment+ViewPager)
- TabLayout与ViewPager的使用
- TabLayout结合ViewPager的使用
- TabLayout+viewpager的简单使用
- 关于TabLayout+ViewPager的用法
- TabLayout+ViewPager遇到的问题
- TabLayout和ViewPager的使用
- POJ 2135 Farm Tour 最小费用流
- 免密认证
- Vim最快上手教程
- Unity 5.x AssetBundle零冗余解决方案
- SQL语句
- 新闻展示的view 库(tablayout+viewpager)
- 笑谈java并发编程一之AtomicBoolean介绍
- 阿里服务器FTP登录用户登录之后无法上传文件的原因排查
- x264的交叉编译和移植
- ubuntu下重装分区问题
- Spring整合jdbcTemplate模板报错
- gc机制--垃圾检测、回收算法
- 第三周(2)——微信被动服务部分
- Hessian入门(传递集合,对象)