Git Product home page Git Product logo

flowhelper's Introduction

FlowHelper

FlowHelper 可以帮助您迅速构建Tab,比如热搜、搜索记录、与ViewPager搭配的工具类;

注意注意注意!!! 提问题的时候,请遵循以下标准

  • 现象: 操作步骤,应用场景
  • 对应代码: 贴图或者贴代码
  • 机型或版本: 可选

后面对描述不清的问题,不予理会,精力有限,感谢理解

具体原理可参考着四篇文章:

如果你也想自己写一个,可以参考以下几篇文章

实现一个可定制化的TabFlowLayout(一) -- 测量与布局

实现一个可定制化的TabFlowLayout(二) -- 实现滚动和平滑过渡

实现一个可定制化的TabFlowLayout(三) -- 动态数据添加与常用接口封装

实现一个可定制化的TabFlowLayout(四) -- 与ViewPager 结合,实现炫酷效果

实现一个可定制化的TabFlowLayout -- 原理篇

实现一个可定制化的TabFlowLayout -- 说明文档

FlowLayout 和 Recyclerview 实现双联表联动

如果您也想快速实现 Banner 轮播图,可以使用这个库 https://github.com/LillteZheng/ViewPagerHelper

工程实际使用 - 玩Android 客户端 : https://github.com/LillteZheng/WanAndroid

使用

在buid.gradle (新版as在setting.gradle)

allprojects {
    repositories {
       ...
        maven { url 'https://jitpack.io' }

    }
}

如果你的工程的是androidx且想支持ViewPager2,可以关联tablibx库

implementation 'com.github.LillteZheng:FlowHelper:v2.3'

support可以关联以下连接,请尽快切到androidx,support包不再维护

 implementation 'com.github.LillteZheng.FlowHelper:tablib:v1.29'

不一定有时间处理,如果工程有不满足或bug,可以修改后提mr

TabFlowLayout 效果图

没有结合ViewPager 结合ViewPager
竖直效果

目前TabFlowLayout 支持以下效果:

  • 矩形
  • 三角形
  • 圆角
  • shape 或者 bitmap 等资源
  • 自定义功能
  • 放大Item效果,与上述效果可共用
  • 颜色渐变效果,需要使用 TabColorTextView 控件,与上述效果可共用,只支持有viewpager 的情况
  • 竖直效果,需要设置 tab_orientation = vertical
  • 宽度均分

TabFlowLayout 使用说明

LabelFlowLayout 效果图

LabelFlowLayout LabelFlowLayout 显示更多

LabelFlowLayout 支持以下效果:

  • 单选
  • 多选
  • 长按
  • 显示更多
  • 收起

LabelFlowLayout 使用说明

其实TabFlowLayout也可以支持底部导航栏,但其实没必要,可以参考这个库 https://github.com/LillteZheng/CusBottomHelper

底部凸起 结合ViewPager

版本信息:

  • v2.5 : 修复TabLabelLayout 在调用 resetStatus,第一个无法点击的问题。并增加 BaseLabelItem,Bean 类继承它,可实现换行
  • v2.3 : 修改TabVpFlowLayout 快速点击时,TabColorTextView 还有残留,和 tab 没有转移过去的问题
  • v2.0 : 内置部分控件,减少接入成本,并优化一些bug,和关闭demo ,viewpager 内存泄露的问题
  • v1.37 : 增加 tab_width_equals_text ,让 rect 根据 text 的长度变化,修复 TabColorTextView 加粗不起作用的问题
  • v1.32 : 修复res和round,tab_margin_x 不起作用的问题
  • v1.30 : 重构分离了ViewPager和非ViewPager的情况,并处理数据增加减少时,notifyDataChange()导致布局混乱的问题
  • v1.291: 修复notifyDataChange部分场景不起作用的问题,小重构了参数配置
  • v1.29 : 修复添加了tabWidth,round和res第一次不起作用的问题
  • v1.28 : 1. 修复底部条跳动的问题;2. 修复TabColorText不能设置padding的问题
  • v1.27 : 修复 tab_color 不起作用的问题
  • v1.26 : 增加 ViewPager2 ....

QQ群

为方便大家交流,创建了一个qq群,群号216618259

如果该项目对您有帮助,赞赏一下吧 ^_^

赞赏名单 方式
*头 微信
*变 微信

参考

本工程参考以下优秀项目:

鸿洋的 flowLayout

Flyco的 TabLayout

flowhelper's People

Contributors

lilltezheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flowhelper's Issues

指示器无法与文字对齐

大佬您好,我的 tab布局如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingEnd="@dimen/dp_30"
    android:paddingBottom="@dimen/sp_6">


    <com.zhengsr.tablib.view.TabColorTextView
        android:id="@+id/item_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:textSize="@dimen/sp_9"
        app:colortext_change_color="@color/color_595cca"
        app:colortext_default_color="@color/color_6f718f"
        tools:text="测试" />


</FrameLayout>

整个tab 设置属性如下:

            <com.zhengsr.tablib.view.flow.TabVpFlowLayout
                android:id="@+id/rectflow"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tab_action_orientaion="left"
                app:tab_width_equals_text="true"
                app:tab_color="@color/colorPrimary"
                app:tab_type="rect" />

最终显示的效果却如下:
image

无论我怎么设置 tab布局 中的 paddingEnd 或者 marginEnd,始终都达不到想要的效果,现在除了想到写死宽度,在设置指示器的宽度,没想到好的方法

默认选择

如何设置默认选择的条目tabflow.setDefaultPosition(0);不生效

有时候setVisualCount无效

我用了您的CusBFragmentUtil配合使用的情况下 第一个被加载的fragment使用TabFlowLayout和viewpager是正常的,但是第二个fragment就会出现TabFlowLayout的tab显示异常 变成xml里原本的宽度了。

比如xml中是match_parent则会一屏只有一个tab,wrap_content就是tab全部粘在一起,但是我确定两个fragment代码都是一样的 均有在xml中配置TabFlowLayout的VisualCount 但是第二个fragment就是不正常 我尝试了在java代码中手动调用setVisualCount并且invalidate仍然不生效,有好的解决方案嘛

TabFlowLayout 当有2个,3个,4个tab时,怎么布局均分并填充

TabFlowLayout 当有2个,3个,4个tab时,怎么布局均分并填充
<com.zhengsr.tablib.view.flow.TabFlowLayout
android:id="@+id/tabFlow"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
TabFlowLayout宽度 当为match_parent时,item宽度也为match_parent时,会导致每个item填充
TabFlowLayout宽度 当为wrap_content时,会显示所有的item,但是不会填充
哪个属性可以均分并填充布局

是否支持下标指示器固定宽度时左对齐

请问下是否支持下标指示器固定宽度的情况下左对齐呢,现在设置app:tab_width="50dp"固定宽度后,如果title文字较长的情况下,指示器是相对文字居中显示的,是否只是左对齐显示呢?

<com.zhengsr.tablib.view.flow.TabFlowLayout
android:id="@+id/resflow"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
app:tab_type="res"
android:background="#6D8FB0"
app:tab_item_res="@drawable/indictor"
app:tab_width="50dp"
app:tab_height="30dp"
app:tab_click_animTime="250"
app:tab_item_autoScale="true"
app:tab_scale_factor="1.2"
app:tab_text_select_color="@color/white"
app:tab_text_unselect_color="@color/unselect"
android:layout_height="wrap_content"/>

final TabVpFlowLayout flowLayout = findViewById(R.id.resflow);

    /**
     * 配置自定义属性
     */

    TabBean bean = new TabBean();
    bean.tabType = FlowConstants.RES;
    bean.tabItemRes = R.drawable.indictor;
    bean.tabClickAnimTime = 300;
    bean.tabMarginLeft = 0;
    bean.tabMarginTop = 70;
    bean.tabWidth = 100;
    bean.tabHeight = 20;
    bean.autoScale = true;
    bean.scaleFactor = 1.2f;
    bean.selectedColor = Color.WHITE;
    bean.unSelectedColor = getResources().getColor(R.color.unselect);
    flowLayout.setTabBean(bean);

    flowLayout.setViewPager(mViewPager);
    flowLayout.setAdapter(new TabFlowAdapter<String>(mTitle));

设置tab_color 无效

    <com.zhengsr.tablib.view.flow.TabFlowLayout
        android:id="@+id/main_tab"
        android:layout_width="wrap_content"
        android:background="@color/white"
        app:tab_type="rect"
        app:tab_color="@color/color_base_color"
        app:tab_height="@dimen/px5"
        app:tab_margin_t="@dimen/px5"
        app:tab_item_autoScale="true"
        app:tab_scale_factor="1.22"
        android:paddingBottom="@dimen/px30"
        android:layout_height="wrap_content" />

这个是使用的代码 下面是效果截图 #3874F6 color_base_color 是蓝色效果
Uploading 1605255866(1).jpg…

吧错误log打上来吧

吧错误log打上来吧

Originally posted by @LillteZheng in #6 (comment)

T-connStch(2)

java.lang.RuntimeException

Cannot make calls to a recycled instance!

解析原始
1 android.content.res.TypedArray.getResources(TypedArray.java:157)
2 android.content.res.XResources$XTypedArray.getDimensionPixelSize(XResources.java:1344)
3 com.zhengsr.tablib.view.action.BaseAction.void autoScaleView()(Unknown Source:3)
4 ##parent##10##parent##
5 ##child## void chooseIndex(int,int)##child##
6 ##child## void chooseSelectedPosition(int)##child##
7 ##child## void config(com.zhengsr.tablib.view.flow.TabFlowLayout)##child##
8 ##child## void configAttrs(android.content.res.TypedArray)##child##
9 ##child## void doAnim(int,int,int)##child##
10 ##child## void draw(android.graphics.Canvas)##child##
11 ##child## com.zhengsr.tablib.bean.TabValue getValue(android.view.View)##child##
12 ##child## void setBean(com.zhengsr.tablib.bean.TabBean)##child##
13 ##child## com.zhengsr.tablib.view.action.BaseAction setViewPager(androidx.viewpager.widget.ViewPager)##child##
14 ##child## void valueChange(com.zhengsr.tablib.bean.TabValue)##child##
15 com.zhengsr.tablib.view.action.RoundAction.void config(com.zhengsr.tablib.view.flow.TabFlowLayout)(Unknown Source:0)
16 ##parent##4##parent##
17 ##child## void configAttrs(android.content.res.TypedArray)##child##
18 ##child## void draw(android.graphics.Canvas)##child##
19 ##child## void setBean(com.zhengsr.tablib.bean.TabBean)##child##
20 ##child## void valueChange(com.zhengsr.tablib.bean.TabValue)##child##
21 com.zhengsr.tablib.view.flow.TabFlowLayout.boolean access$100(com.zhengsr.tablib.view.flow.TabFlowLayout)(Unknown Source:63)
22 ##parent##2##parent##
23 ##child## boolean access$802(com.zhengsr.tablib.view.flow.TabFlowLayout,boolean)##child##
24 ##child## void chooseTabTpye(int)##child##
25 com.zhengsr.tablib.view.flow.TabFlowLayout.void access$000(com.zhengsr.tablib.view.flow.TabFlowLayout)(Unknown Source:10)
26 ##parent##9##parent##
27 ##child## boolean access$102(com.zhengsr.tablib.view.flow.TabFlowLayout,boolean)##child##
28 ##child## void access$600(com.zhengsr.tablib.view.flow.TabFlowLayout,android.view.View,boolean)##child##
29 ##child## void access$900(com.zhengsr.tablib.view.flow.TabFlowLayout,int,android.view.View)##child##
30 ##child## void chooseItem(int,android.view.View)##child##
31 ##child## void configClick(android.view.View,int)##child##
32 ##child## boolean isLabelFlow()##child##
33 ##child## com.zhengsr.tablib.view.flow.TabFlowLayout setDefaultPosition(int)##child##
34 ##child## com.zhengsr.tablib.view.flow.TabFlowLayout setTabBean(com.zhengsr.tablib.bean.TabBean)##child##
35 ##child## void updateScroll(android.view.View,boolean)##child##
36 com.movies.k8.fragment.HomeTabMovies.void access$100(com.movies.k8.fragment.HomeTabMovies)(Unknown Source:210)
37 ##parent##3##parent##
38 ##child## java.lang.String access$302(com.movies.k8.fragment.HomeTabMovies,java.lang.String)##child##
39 ##child## void inView(android.view.View)##child##
40 ##child## void loadMore(com.movies.k8.bean.HomeCategoryBean)##child##
41 com.movies.k8.fragment.HomeTabMovies.me.bakumon.statuslayoutmanager.library.StatusLayoutManager access$000(com.movies.k8.fragment.HomeTabMovies)(Unknown Source:0)
42 ##parent##7##parent##
43 ##child## java.lang.String access$202(com.movies.k8.fragment.HomeTabMovies,java.lang.String)##child##
44 ##child## void initView(android.view.View)##child##
45 ##child## void lambda$loadDone$0(com.github.nukc.LoadMoreWrapper.LoadMoreAdapter$Enabled)##child##
46 ##child## void loadDone(com.movies.k8.bean.HomeCategoryBean)##child##
47 ##child## void loadError()##child##
48 ##child## com.movies.k8.fragment.HomeTabMovies newInstance(int,java.lang.String)##child##
49 ##child## void onRefresh(com.scwang.smartrefresh.layout.api.RefreshLayout)##child##
50 com.movies.k8.fragment.BaseFragment.onCreateView(Unknown Source:17)
51 androidx.fragment.app.Fragment.performCreateView(Unknown Source:15)
52 androidx.fragment.app.FragmentManagerImpl.moveToState(Unknown Source:684)
53 androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(Unknown Source:105)
54 androidx.fragment.app.FragmentManagerImpl.moveToState(Unknown Source:46)
55 androidx.fragment.app.BackStackRecord.executeOps(Unknown Source:177)
56 androidx.fragment.app.FragmentManagerImpl.executeOps(Unknown Source:38)
57 androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(Unknown Source:114)
58 androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(Unknown Source:88)
59 androidx.fragment.app.FragmentManagerImpl.execSingleAction(Unknown Source:31)
60 androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(Unknown Source:6)
61 androidx.fragment.app.FragmentPagerAdapter.finishUpdate(Unknown Source:4)
62 androidx.viewpager.widget.ViewPager.populate(Unknown Source:385)
63 androidx.viewpager.widget.ViewPager.populate(Unknown Source:2)
64 androidx.viewpager.widget.ViewPager.onMeasure(Unknown Source:194)
65 android.view.View.measure(View.java:23389)
66 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6770)
67 android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
68 android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
69 android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
70 android.view.View.measure(View.java:23389)
71 androidx.viewpager.widget.ViewPager.onMeasure(Unknown Source:239)
72 android.view.View.measure(View.java:23389)
73 android.widget.LinearLayout.measureVertical(LinearLayout.java:978)
74 android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
75 android.view.View.measure(View.java:23389)
76 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6770)
77 android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
78 androidx.appcompat.widget.ContentFrameLayout.onMeasure(Unknown Source:156)
79 android.view.View.measure(View.java:23389)
80 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6770)
81 android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
82 android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
83 android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
84 android.view.View.measure(View.java:23389)
85 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6770)
86 android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
87 android.view.View.measure(View.java:23389)
88 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6770)
89 android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
90 android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
91 android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
92 android.view.View.measure(View.java:23389)
93 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6770)
94 android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
95 com.android.internal.policy.DecorView.onMeasure(DecorView.java:717)
96 android.view.View.measure(View.java:23389)
97 android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3064)
98 android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1881)
99 android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2173)
100 android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1769)
101 android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7946)
102 android.view.Choreographer$CallbackRecord.run(Choreographer.java:1312)
103 android.view.Choreographer.doCallbacks(Choreographer.java:1123)
104 android.view.Choreographer.doFrame(Choreographer.java:941)
105 android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:1227)
106 android.os.Handler.dispatchMessage(Handler.java:106)
107 android.os.Looper.loop(Looper.java:193)
108 android.app.ActivityThread.main(ActivityThread.java:7009)
109 java.lang.reflect.Method.invoke(Native Method)
110 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
111 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

TabFlowLayout 默认n后 在选择第 n-1 或者n+1个选择bug

TabFlowLayout 默认n后 在选择第 n-1 或者n+1个选择bug
和LabelFlowLayout如出一辙的问题

是这样的,由A界面进入B界面,B界面是用的TabFlowLayout ,在进入B界面我会根据用户先前保存的选择,进行回显默认选择,比如进入页面初始化TabFlowLayout后调用 flowLayout.setItemSelected(3);
这时候确是第3个标签是选中,但这时候去选择第2 或者第4个 tab的时候 mViewPager变了,但2 或者4的状态颜色不对,但选择其他后就正常了

请大佬看下这个问题 Cannot make calls to a recycled instance!

main(2)

java.lang.RuntimeException

Cannot make calls to a recycled instance!

1 android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:768)
2 com.zhengsr.tablib.view.action.BaseAction.configAttrs(BaseAction.java:552)
3 com.zhengsr.tablib.view.flow.TabFlowLayout.chooseTabTpye(TabFlowLayout.java:186)
4 com.zhengsr.tablib.view.flow.TabFlowLayout.setTabBean(TabFlowLayout.java:645)
5 net.xx.CompetitionFragment.initFragment(CompetitionFragment.java:242)
6 net.xx.CompetitionFragment.onViewCreated(CompetitionFragment.java:82)
7 androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:892)
8 androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
9 androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
10 androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
11 androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
12 androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
13 androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
14 androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
15 androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2663)
16 androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManagerImpl.java:2613)
17 androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:246)
18 androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:542)
19 androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:210)
20 android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1433)
21 android.app.Activity.performStart(Activity.java:7924)
22 android.app.ActivityThread.handleStartActivity(ActivityThread.java:3332)
23 android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
24 android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
25 android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
26 android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
27 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2044)
28 android.os.Handler.dispatchMessage(Handler.java:107)
29 android.os.Looper.loop(Looper.java:224)
30 android.app.ActivityThread.main(ActivityThread.java:7551)
31 java.lang.reflect.Method.invoke(Native Method)
32 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
33 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

tab标签选项较多会出现显示错乱

1.30版本
数量少时显示正常,多的时候就会出现tab横线位置不跟随,或者跟随错误,上一个选项文字变大了不会缩小等
image
image
image
` @BindView(R.id.viewpager)
ViewPager2 viewpager;
@BindView(R.id.rectflow)
TabVpFlowLayout flowLayout;
private FragmentManager fragmentManager = getSupportFragmentManager();
private List mFragments = new ArrayList<>();
private List mTitle = Arrays.asList("领用", "退还", "借用", "归还", "变更", "调拨", "维修", "处置");
@OverRide
protected void onCreate(@nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_fixed_bill_list);
ButterKnife.bind(this);
super.onCreate(savedInstanceState);
Fragment fragment = new LYBliiList();
mFragments.add(fragment);
fragment = new THBliiList();
mFragments.add(fragment);
fragment = new JYBliiList();
mFragments.add(fragment);
fragment = new GHBliiList();
mFragments.add(fragment);
fragment = new BGBliiList();
mFragments.add(fragment);
fragment = new DBBliiList();
mFragments.add(fragment);
fragment = new WXBliiList();
mFragments.add(fragment);
fragment = new CZBliiList();
mFragments.add(fragment);
viewpager.setAdapter(new Fragment2Adapter(fragmentManager,getLifecycle(), mFragments));
rectFlow();
}

private void rectFlow() {
    //设置数据,这里以 setAdapter 的形式
    flowLayout.setViewPager(viewpager);
    TabConfig config = new TabConfig.Builder()
            .setViewpager(viewpager)
            .setTextId(R.id.item_text)
            .setSelectedColor(Color.BLUE)
            .setUnSelectColor(getResources().getColor(R.color.unselect))
            .build();
    flowLayout.setAdapter(config,new TabFlowAdapter<String>(R.layout.item_msg, mTitle) {
        @Override
        public void onItemSelectState(View view, boolean isSelected) {
            super.onItemSelectState(view, isSelected);
            //选中时,可以改变不同颜色,如果你的background 为 selector,可以不写这个
            if (isSelected) {
                setTextColor(view, R.id.item_text, Color.BLUE);
            } else {
                setTextColor(view, R.id.item_text, getResources().getColor(R.color.unselect));
            }
        }

        @Override
        public void onItemClick(View view, String data, int position) {
            super.onItemClick(view, data, position);
            viewpager.setCurrentItem(position);
        }

        @Override
        public void bindView(View view, String data, int position) {
            /**
             * 绑定数据,可以使用 setText(..) 等快捷方式,也可以视同 view.findViewById()
             * 同时,当你的子控件需要点击事件时,可以通过  addChildrenClick() 注册事件,
             * 然后重写 onItemChildClick(..) 即可拿到事件,否则就自己写。
             * 自己的点击和长按不需要注册
             */
            setText(view, R.id.item_text, data)
                    .setTextColor(view, R.id.item_text, getResources().getColor(R.color.unselect));

        }
    });

// flowLayout.setViewPager(viewpager).setTextId(R.id.item_text)
// .setSelectedColor(Color.BLUE)//必填,不然 Textview 没效果
// .setUnSelectedColor(getResources().getColor(R.color.unselect));
}`

布局边界bug

image

我在约束布局中如上图布局,TabFlowLayout与ViewPager配合使用;
当tab较多时,滑动至最后1个tab时,最后一个tab无法显示;实际最后一个tab存在,但是在右边界的外部;
如上图,TabFlowLayout的右边界是iv_workbench_rank的左侧,显示中TabFlowLayout的右边界也确实如此,但是tab的排布和加载实际已经到了iv_workbench_rank的位置,所以无法显示

TabVpFlowLayout+ViewPager2 实现垂直tab切换Viewpager时无法加入指示器吗?

提供的demo是TabFlowLayout+recycleView ,现在需要垂直的tab去切换viewpager .就使用了TabVpFlowLayout+ViewPager2. 目前tab切换viewpager是可以的,但是添加的指示器无法显示.设置TabVpFlowLayout为horizontal时 矩形指示器会显示出来,TabVpFlowLayout设置为vertical ,矩形指示器就不显示了. 尝试过TabBean去实现 也失败了.

需求收集

这个为需求收集列表

格式要求:

  1. 需求描述
  2. 应用场景
  3. 参考效果 (选填)

notifyDataChanged 导致tab_visual_count设置的文字显示错乱

进入页面的时候数据显示是正常的
QQ图片20210608175540

使用 flowLayout.getAdapter().notifyDataChanged();
QQ图片247

文字会全部到左边来,下方横线正常
关键代码
`mTitle = Arrays.asList(String.format("未盘(%s)",inventorySubListBean.getCheckingNum()),
String.format("已盘(%s)",inventorySubListBean.getCheckedNum()),
String.format("新增资产(%s)",inventorySubListBean.getNewNum()));
private void rectFlow() {
//设置数据,这里以 setAdapter 的形式
flowLayout.setAdapter(new TabFlowAdapter(R.layout.item_msg, mTitle) {
@OverRide
public void onItemSelectState(View view, boolean isSelected) {
super.onItemSelectState(view, isSelected);
//选中时,可以改变不同颜色,如果你的background 为 selector,可以不写这个
if (isSelected) {
setTextColor(view, R.id.item_text, Color.BLUE);
} else {
setTextColor(view, R.id.item_text, getResources().getColor(R.color.unselect));
current = 1;
updateAll(current, size, assetsStatus, "resh");
}
}

        @Override
        public void onItemClick(View view, String data, int position) {
            super.onItemClick(view, data, position);
            switch (position) {
                case 0:
                    assetsStatus="未盘";
                    break;
                case 1:
                    assetsStatus="已盘";
                    break;
                case 2:
                    assetsStatus="新增资产";
                    break;
            }
        }

        @Override
        public void bindView(View view, String data, int position) {
            /**
             * 绑定数据,可以使用 setText(..) 等快捷方式,也可以视同 view.findViewById()
             * 同时,当你的子控件需要点击事件时,可以通过  addChildrenClick() 注册事件,
             * 然后重写 onItemChildClick(..) 即可拿到事件,否则就自己写。
             * 自己的点击和长按不需要注册
             */
            setText(view, R.id.item_text, data)
                    .setTextColor(view, R.id.item_text, getResources().getColor(R.color.unselect));

        }
    });
}`

<com.zhengsr.tablib.view.flow.TabFlowLayout android:id="@+id/rectflow" android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginTop="5dp" android:background="#FFFFFF" app:tab_color="@color/colorToolBar" app:tab_height="3dp" app:tab_item_autoScale="true" app:tab_margin_t="6dp" app:tab_scale_factor="1.3" app:tab_type="rect" app:tab_visual_count="3" />
`
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

<TextView
    android:id="@+id/item_text"
    android:layout_width="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    tools:text="测试"
    android:paddingTop="6dp"
    android:paddingBottom="6dp"
    android:paddingStart="12dp"
    android:paddingEnd="12dp"
    android:textSize="14sp"
    android:gravity="center"
    android:textColor="@color/unselect"
    android:layout_height="wrap_content"/>

<TextView
    android:layout_width="5dp"
    android:layout_height="5dp"
    android:gravity="center"
    android:textSize="8dp"
    android:background="@drawable/shape_red_radius"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_margin="5dp"
    android:visibility="gone"
    />

</android.support.constraint.ConstraintLayout>`

老哥,跑了下demo有几点问题想反馈下😂

第一个是结合viewpager使用时点击指示器切换viewpager时卡卡的,还内存泄漏了😂

微信图片_20220130203850

第二个是竖直效果滑动recyclerview时左侧的TabFlowLayout经常不动,有时候rv还会闪现,还有rv空白的地方好像不能滑动😂

最后一个是支持显示更多的那个demo,收起时点击rv,也是会突然瞬移到看不见的地方😂

显示bug

相邻的两个tab 点击 ,指示器 动画出现异常,隔开一个是正常的。

LabelFlowLayout 第0个选择bug

LabelFlowLayout 如果设置不选中0个,比如设置 flowLayout.setSelects(10);
这时候第0个无法选择,点击没有任何反应

TabFlowLayout选中和未选中

TabFlowLayout选中时字体加粗和字号变大
TabFlowLayout未选中时字体不加粗和字号不变大
用哪个属性啊

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.