diff --git a/Label_README.md b/Label_README.md
index 943cbbb..229f091 100644
--- a/Label_README.md
+++ b/Label_README.md
@@ -17,6 +17,14 @@ LabelFlowLayout 竖向布局,支持自动换行,单选、多选、长按等
**它的状态变化,根据 view 的 selected 来,所以大家可以写 selector 当背景,或者在方法中自己设置**
+
+**LabelFlowLayout 支持以下效果:**
+- **单选**
+- **多选**
+- **长按**
+- **显示更多**
+- **收起**
+
### 3.3.1 使用
LabelFlowLayout 默认单选,在 xml 这样配置:
diff --git a/README.md b/README.md
index 020ba89..f5b6aea 100644
--- a/README.md
+++ b/README.md
@@ -42,7 +42,7 @@ allprojects {
```
```
-implementation 'com.github.LillteZheng:FlowHelper:v1.21'
+implementation 'com.github.LillteZheng:FlowHelper:v1.22'
```
**如果要支持 AndroidX ,如果你的工程已经有以下代码,直接关联即可:**
@@ -77,6 +77,17 @@ android.enableJetifier=true
+**目前TabFlowLayout 支持以下效果:**
+- **矩形**
+- **三角形**
+- **圆角**
+- **shape 或者 bitmap 等资源**
+- **自定义功能**
+- **放大Item效果,与上述效果可共用**
+- **颜色渐变效果,需要使用 TabColorTextView 控件,与上述效果可共用,只支持有viewpager 的情况**
+- **竖直效果,需要设置 tab_orientation = vertical**
+- **宽度均分**
+
[TabFlowLayout 使用说明](https://github.com/LillteZheng/FlowHelper/blob/master/TAB_README.md)
## LabelFlowLayout 效果图
@@ -93,6 +104,15 @@ android.enableJetifier=true
+
+**LabelFlowLayout 支持以下效果:**
+- **单选**
+- **多选**
+- **长按**
+- **显示更多**
+- **收起**
+
+
[LabelFlowLayout 使用说明](https://github.com/LillteZheng/FlowHelper/blob/master/Label_README.md)
diff --git a/TAB_README.md b/TAB_README.md
index 36e8a4c..7a3d3c6 100644
--- a/TAB_README.md
+++ b/TAB_README.md
@@ -32,6 +32,7 @@
- **放大Item效果,与上述效果可共用**
- **颜色渐变效果,需要使用 TabColorTextView 控件,与上述效果可共用,只支持有viewpager 的情况**
- **竖直效果,需要设置 tab_orientation = vertical**
+- **宽度均分**
## 三、使用
@@ -286,7 +287,16 @@ private void resFlow(){
```
通过重写 valueChange 拿到移动偏移量,然后通过 flowLayout.setAction(new CircleAction()) 即可。如果是竖直方向,拿到 value.top,value.bottom 再去写逻辑即可。
-### 3.1.4、参考代码
+### 3.1.4 宽度均分
+
+上面中,item_layout 的宽度都是通过测量自身的,如果想要均分宽度怎么做呢?
+
+可以设置 tab_visual_count ,当前可视个数来试下,比如当前可视界面只显示3个:
+
+
+
+
+### 3.1.5、参考代码
上面的效果,可以参考以下代码:
@@ -343,7 +353,7 @@ private void resFlow(){
|tab_orientation|integer|vertical竖直防线,horizontal横向,默认横向|
|tab_action_orientaion|integer|left坐标,right右边,只支持 tri、rect 两种效果|
|tab_isAutoScroll|boolean|是否支持自动滚动,默认为true|
-
+|tab_visual_count|integer|可视化个数,比如有一排,我们就只要显示4个,此时宽度均分|
**TabColorTextView**
diff --git a/app/src/main/java/com/zhengsr/tabhelper/activity/TabActivity.java b/app/src/main/java/com/zhengsr/tabhelper/activity/TabActivity.java
index 107c0c2..535d731 100644
--- a/app/src/main/java/com/zhengsr/tabhelper/activity/TabActivity.java
+++ b/app/src/main/java/com/zhengsr/tabhelper/activity/TabActivity.java
@@ -57,7 +57,7 @@ private void rectFlow(){
.setTextId(R.id.item_text)
.setSelectedColor(Color.WHITE)
.setUnSelectedColor(getResources().getColor(R.color.unselect));
- flowLayout.setAdapter(new TabFlowAdapter(R.layout.item_msg,mTitle) {
+ flowLayout.setAdapter(new TabFlowAdapter(R.layout.item_test,mTitle) {
@Override
public void bindView(View view, String data, int position) {
setText(view,R.id.item_text,data);
diff --git a/app/src/main/java/com/zhengsr/tabhelper/activity/TabNoViewPagerActivity.java b/app/src/main/java/com/zhengsr/tabhelper/activity/TabNoViewPagerActivity.java
index 966d016..3da5f20 100644
--- a/app/src/main/java/com/zhengsr/tabhelper/activity/TabNoViewPagerActivity.java
+++ b/app/src/main/java/com/zhengsr/tabhelper/activity/TabNoViewPagerActivity.java
@@ -62,7 +62,7 @@ public void bindView(View view, String data, int position) {
});
TabFlowLayout flowLayout2 = findViewById(R.id.rectflow2);
- flowLayout2.setAdapter(new TabFlowAdapter(R.layout.item_msg,mTitle) {
+ flowLayout2.setAdapter(new TabFlowAdapter(R.layout.item_test,mTitle) {
@Override
public void bindView(View view, String data, int position) {
setText(view,R.id.item_text,data);
diff --git a/app/src/main/res/layout/activity_tab.xml b/app/src/main/res/layout/activity_tab.xml
index 14cfaad..9d162ed 100644
--- a/app/src/main/res/layout/activity_tab.xml
+++ b/app/src/main/res/layout/activity_tab.xml
@@ -29,6 +29,8 @@
android:background="@color/black_ff_bg"
app:tab_scale_factor="1.2"
app:tab_item_autoScale="true"
+ app:tab_visual_count="4"
+ android:layout_marginStart="20dp"
android:layout_height="wrap_content"/>
+
+
+
\ No newline at end of file
diff --git a/gif/tab_viewpager.gif b/gif/tab_viewpager.gif
index fa1b777..aa1a053 100644
Binary files a/gif/tab_viewpager.gif and b/gif/tab_viewpager.gif differ
diff --git a/gif/tab_visual_count.png b/gif/tab_visual_count.png
new file mode 100644
index 0000000..1919376
Binary files /dev/null and b/gif/tab_visual_count.png differ
diff --git a/tablib/src/main/java/com/zhengsr/tablib/bean/TabBean.java b/tablib/src/main/java/com/zhengsr/tablib/bean/TabBean.java
index b530728..b256c18 100644
--- a/tablib/src/main/java/com/zhengsr/tablib/bean/TabBean.java
+++ b/tablib/src/main/java/com/zhengsr/tablib/bean/TabBean.java
@@ -68,6 +68,11 @@ public class TabBean {
*/
public boolean isAutoScroll = true;
+ /**
+ * 可视个数
+ */
+ public int visualCount = -1;
+
@Override
public String toString() {
diff --git a/tablib/src/main/java/com/zhengsr/tablib/view/flow/FlowLayout.java b/tablib/src/main/java/com/zhengsr/tablib/view/flow/FlowLayout.java
index b4e5fbd..5285e68 100644
--- a/tablib/src/main/java/com/zhengsr/tablib/view/flow/FlowLayout.java
+++ b/tablib/src/main/java/com/zhengsr/tablib/view/flow/FlowLayout.java
@@ -22,9 +22,13 @@ class FlowLayout extends ViewGroup {
private static final String TAG = "FlowLayout";
protected int mViewWidth;
protected int mViewHeight;
+ /**
+ * tabflowlayout
+ */
private int mTabOrientation;
+ protected int mVisualCount = -1;
/**
- * label
+ * labelflowlayout
*/
private List mLineHeights = new ArrayList<>();
private List> mAllViews = new ArrayList<>();
@@ -60,6 +64,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
}
+ public void setVisualCount(int visualCount){
+ mVisualCount = visualCount;
+ }
/**
* 设置行数
@@ -150,7 +157,17 @@ private void measureTabHorizontal(int widthMeasureSpec, int heightMeasureSpec) {
* 计算宽高
*/
+
+ int widthPixels = getResources().getDisplayMetrics().widthPixels;
+ if (MeasureSpec.EXACTLY == widthMode) {
+ widthPixels = widthSize;
+ }
+
+
for (int i = 0; i < childCount; i++) {
+
+
+
View child = getChildAt(i);
if (child.getVisibility() == View.GONE) {
continue;
@@ -158,15 +175,24 @@ private void measureTabHorizontal(int widthMeasureSpec, int heightMeasureSpec) {
measureChild(child, widthMeasureSpec, heightMeasureSpec);
MarginLayoutParams params = (MarginLayoutParams) child.getLayoutParams();
-
//拿到 子控件宽高 + margin
- int cw = child.getMeasuredWidth() + params.leftMargin + params.rightMargin;
+ int cw;
+ if (mVisualCount != -1){
+ cw = widthPixels/mVisualCount;
+ params.width = cw;
+ child.setLayoutParams(params);
+ width = widthPixels;
+ }else{
+ cw = child.getMeasuredWidth() + params.leftMargin + params.rightMargin;
+ width += cw;
+ }
int ch = child.getMeasuredHeight() + params.topMargin + params.bottomMargin;
-
- width += cw;
//拿到 子控件高度,拿到最大的那个高度
height = Math.max(height, ch);
+
+
+
}
//具体大小,padding不受影响
diff --git a/tablib/src/main/java/com/zhengsr/tablib/view/flow/ScrollFlowLayout.java b/tablib/src/main/java/com/zhengsr/tablib/view/flow/ScrollFlowLayout.java
index 1c1ecfa..7506463 100644
--- a/tablib/src/main/java/com/zhengsr/tablib/view/flow/ScrollFlowLayout.java
+++ b/tablib/src/main/java/com/zhengsr/tablib/view/flow/ScrollFlowLayout.java
@@ -70,6 +70,7 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
/**
* TabFlowLayout 或者 LabelFlowLayout 的竖向滚动
*/
+ //todo 这是什么魔性 if else 找机会改一下
if (isVerticalMove()){
if (mViewHeight < mScreenHeight){
if (mBottomRound > mViewHeight){
@@ -95,22 +96,32 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
}else{
//TabFlowLayout 横向布局
if (!isVertical()) {
- //说明控件没有满屏或者固定宽度
- if (mViewWidth < mScreenWidth) {
- if (mRightBound > mViewWidth) {
+ //如果是固定宽度
+ if (mVisualCount != -1){
+ if (getChildCount() > mVisualCount){
isCanMove = true;
- } else {
+ }else{
isCanMove = false;
}
mWidth = mViewWidth;
- } else {
- //再确认一遍
- if (mRightBound > mScreenWidth) {
- isCanMove = true;
+ }else {
+ //说明控件没有满屏或者固定宽度
+ if (mViewWidth < mScreenWidth) {
+ if (mRightBound > mViewWidth) {
+ isCanMove = true;
+ } else {
+ isCanMove = false;
+ }
+ mWidth = mViewWidth;
+ } else {
+ //再确认一遍
+ if (mRightBound > mScreenWidth) {
+ isCanMove = true;
+ }
+ mWidth = mScreenWidth;
}
- mWidth = mScreenWidth;
}
- if (!isTabAutoScroll()){
+ if (!isTabAutoScroll()) {
isCanMove = false;
}
}
diff --git a/tablib/src/main/java/com/zhengsr/tablib/view/flow/TabFlowLayout.java b/tablib/src/main/java/com/zhengsr/tablib/view/flow/TabFlowLayout.java
index 12b8e7c..804bbcf 100644
--- a/tablib/src/main/java/com/zhengsr/tablib/view/flow/TabFlowLayout.java
+++ b/tablib/src/main/java/com/zhengsr/tablib/view/flow/TabFlowLayout.java
@@ -82,6 +82,8 @@ public TabFlowLayout(Context context, @Nullable AttributeSet attrs, int defStyle
mScroller = new Scroller(getContext());
mTabOrientation = mTypeArray.getInteger(R.styleable.TabFlowLayout_tab_orientation,FlowConstants.HORIZONTATAL);
isAutoScroll = mTypeArray.getBoolean(R.styleable.TabFlowLayout_tab_isAutoScroll,true);
+ int visualCount = mTypeArray.getInteger(R.styleable.TabFlowLayout_tab_visual_count, -1);
+ setVisualCount(visualCount);
setTabOrientation(mTabOrientation);
chooseTabTpye(tabStyle);
setLayerType(LAYER_TYPE_SOFTWARE,null);
@@ -117,11 +119,7 @@ public void onGlobalLayout() {
if (mViewPager == null) {
updateScroll(view, false);
}
-
}
-
-
-
}
getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
@@ -663,6 +661,9 @@ public TabFlowLayout setTabBean(TabBean bean){
if (isAutoScroll != bean.isAutoScroll){
isAutoScroll = bean.isAutoScroll;
}
+ if (bean.visualCount != -1){
+ setVisualCount(bean.visualCount);
+ }
return this;
}
diff --git a/tablib/src/main/res/values/attrs.xml b/tablib/src/main/res/values/attrs.xml
index e56eae2..e234d80 100644
--- a/tablib/src/main/res/values/attrs.xml
+++ b/tablib/src/main/res/values/attrs.xml
@@ -20,6 +20,7 @@
+