Skip to content

Commit

Permalink
1、LabelFlowLayout 支持竖直滚动
Browse files Browse the repository at this point in the history
2、TabFlowLayaout 增加功能,action 也全部增加
  • Loading branch information
LillteZheng committed Jan 23, 2020
1 parent 60da8a2 commit a451ebc
Show file tree
Hide file tree
Showing 29 changed files with 774 additions and 203 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ allprojects {
```

```
implementation 'com.github.LillteZheng:FlowHelper:v1.14'
implementation 'com.github.LillteZheng:FlowHelper:v1.15'
//如果要使用 androidx,用下面这个
implementation 'com.github.LillteZheng:FlowHelperX:v1.14'
```
Expand All @@ -47,6 +47,16 @@ implementation 'com.github.LillteZheng:FlowHelperX:v1.14'

</table>

<table align="center">
<tr>
<th>竖直效果</th>
</tr>
<tr>
<td><a href="url"><img src="https://github.com/LillteZheng/FlowHelper/raw/master/gif/tab_vertical.gif" align="left"height="789" width="479"></a></td>
</tr>

</table>

[TabFlowLayout 使用说明](https://github.com/LillteZheng/FlowHelper/blob/master/TAB_README.md)

## LabelFlowLayout 效果图
Expand Down
18 changes: 17 additions & 1 deletion TAB_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,26 @@

</table>


<table align="center">
<tr>
<th>竖直效果</th>
</tr>
<tr>
<td><a href="url"><img src="https://github.com/LillteZheng/FlowHelper/raw/master/gif/tab_vertical.gif" align="left"height="789" width="479"></a></td>
</tr>

</table>

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


### 1、正常使用
Expand Down Expand Up @@ -222,6 +234,10 @@ private void resFlow(){
|tab_click_animTime|integer|点击动画的时间,默认300ms|
|tab_item_autoScale|boolean|开启放大缩小的效果|
|tab_scale_factor|float|放大倍数|
|tab_orientation|integer|vertical竖直防线,horizontal横向,默认横向|
|tab_action_orientaion|integer|left坐标,right右边,只支持 tri、rect 两种效果|



**TabColorTextView**

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zhengsr.tabhelper">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
Expand All @@ -11,7 +11,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".activity.NetTestActivity"></activity>
<activity android:name=".activity.VerticalTabActivity"></activity>
<activity android:name=".activity.NetTestActivity" />
<activity android:name=".activity.LabelActivity" />
<activity android:name=".activity.TabNoViewPagerActivity" />
<activity android:name=".activity.TabActivity" />
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/zhengsr/tabhelper/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import com.zhengsr.tabhelper.activity.NetTestActivity;
import com.zhengsr.tabhelper.activity.TabActivity;
import com.zhengsr.tabhelper.activity.TabNoViewPagerActivity;
import com.zhengsr.tabhelper.activity.VerticalTabActivity;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// startActivity(new Intent(this, LabelActivity.class));
// startActivity(new Intent(this, VerticalTabActivity.class));
}


Expand All @@ -36,4 +37,8 @@ public void labelflow(View view) {
public void tablayout3(View view) {
startActivity(new Intent(this, NetTestActivity.class));
}

public void tablayout4(View view) {
startActivity(new Intent(this,VerticalTabActivity.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void config(TabFlowLayout parentView) {
float t = parentView.getPaddingTop() + child.getMeasuredHeight() - mTabHeight/2 -mMarginBottom;
float r = mTabWidth + l;
float b = child.getMeasuredHeight() - mMarginBottom;
mRect.set(l,t,r,b);
mTabRect.set(l,t,r,b);
}
}

Expand All @@ -215,12 +215,12 @@ public void config(TabFlowLayout parentView) {
protected void valueChange(TabValue value) {
super.valueChange(value);
//由于自定义的,都是从left 开始算起的,所以这里还需要加上圆的半径
mRect.left = value.left + mTabWidth/2;
mTabRect.left = value.left + mTabWidth/2;
}

@Override
public void draw(Canvas canvas) {
canvas.drawCircle(mRect.left,mRect.top,mTabWidth/2,mPaint);
canvas.drawCircle(mTabRect.left, mTabRect.top,mTabWidth/2,mPaint);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void config(TabFlowLayout parentView) {
float t = parentView.getPaddingTop() + child.getMeasuredHeight() - mTabHeight/2 -mMarginBottom;
float r = mTabWidth + l;
float b = child.getMeasuredHeight() - mMarginBottom;
mRect.set(l,t,r,b);
mTabRect.set(l,t,r,b);
}
}

Expand All @@ -167,12 +167,12 @@ protected void valueChange(TabValue value) {
* Rect 为这个偏移量的局域。
*/
//由于自定义的,都是从left 开始算起的,所以这里还需要加上圆的半径
mRect.left = value.left + mTabWidth/2;
mTabRect.left = value.left + mTabWidth/2;
}

@Override
public void draw(Canvas canvas) {
canvas.drawCircle(mRect.left,mRect.top,mTabWidth/2,mPaint);
canvas.drawCircle(mTabRect.left, mTabRect.top,mTabWidth/2,mPaint);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.zhengsr.tabhelper.activity;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.zhengsr.tabhelper.R;
import com.zhengsr.tablib.view.adapter.TabFlowAdapter;
import com.zhengsr.tablib.view.flow.TabFlowLayout;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class VerticalTabActivity extends AppCompatActivity {
private List<String> mTitle = new ArrayList<>(Arrays.asList("Life is like an ocean Only strong willed people can reach the other side i am shao rui zheng xiao yuan".split(" ")));
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vertical_tab);
TabFlowLayout flowLayout = findViewById(R.id.tabflow);
flowLayout.setAdapter(new TabFlowAdapter<String>(R.layout.item_msg,mTitle) {
@Override
public void bindView(View view, String data, int position) {
setText(view,R.id.item_text,data);
}
});
}
}
1 change: 1 addition & 0 deletions app/src/main/res/drawable/shape_round_trans.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/black_ff_bg"/>
<corners android:radius="10dp"/>
</shape>
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
android:textAllCaps="false"
android:onClick="tablayout2"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TabFlowLayout 竖直效果"
android:textAllCaps="false"
android:onClick="tablayout4"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -37,4 +44,5 @@
android:onClick="labelflow"/>



</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_tab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
android:background="#6D8FB0"
app:tab_color="#b01a1a1a"
app:tab_round_size="4dp"
app:tab_margin_t="5dp"
app:tab_margin_t="3dp"
app:tab_margin_b="3dp"
app:tab_margin_l="2dp"
app:tab_margin_r="2dp"
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/layout/activity_tab_no_view_pager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@

android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
app:tab_click_animTime="250"
android:layout_height="wrap_content"/>

Expand Down
28 changes: 28 additions & 0 deletions app/src/main/res/layout/activity_vertical_tab.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activity.VerticalTabActivity">



<com.zhengsr.tablib.view.flow.TabFlowLayout
android:id="@+id/tabflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:tab_orientation="vertical"
android:background="@color/black_ff_bg"
app:tab_type="round"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
app:tab_scale_factor="1.2"
app:tab_item_autoScale="true"
app:tab_color="@color/colorPrimary"
/>

</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/layout/item_msg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:textSize="14sp"
android:gravity="center"
android:textColor="@color/unselect"
android:layout_height="wrap_content"/>

Expand Down
17 changes: 17 additions & 0 deletions app/src/main/res/layout/item_text_width_match.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_text"
android:layout_width="wrap_content"
tools:text="测试"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:textSize="14sp"
android:gravity="center"
android:background="#30ff0000"
android:textColor="@color/wechat"
android:layout_height="wrap_content">

</TextView>
Binary file modified gif/label.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gif/tab_vertical.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions tablib/src/main/java/com/zhengsr/tablib/FlowConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ public class FlowConstants {
public static final int COLOR = 3;
public static final int RES = 4;

public static final int VERTICAL = 1;
public static final int HORIZONTATAL = 2;

public static final int LEFT = 1;
public static final int RIGHT = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class TabTypeEvaluator implements TypeEvaluator<TabValue> {
public TabValue evaluate(float fraction, TabValue startValue, TabValue endValue) {
//这里都采用匀速
value.left = startValue.left + fraction * (endValue.left - startValue.left);
value.top = startValue.top + fraction * (endValue.top - startValue.top);
value.bottom = startValue.bottom + fraction * (endValue.bottom - startValue.bottom);
value.right = startValue.right + fraction * (endValue.right - startValue.right);
return value;
}
Expand Down
51 changes: 35 additions & 16 deletions tablib/src/main/java/com/zhengsr/tablib/bean/TabValue.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
package com.zhengsr.tablib.bean;

import android.graphics.RectF;
import android.util.TypedValue;

public class TabValue {
public float left;
public float right;
public float left;
public float top;
public float right;
public float bottom;

public TabValue(float left, float right) {
this.left = left;
this.right = right;
}

public TabValue() {
}

public TabValue(float left, float right) {
this.left = left;
this.right = right;
}
@Override
public String toString() {
return "TabValue{" +
"left=" + left +
", top=" + top +
", right=" + right +
", bottom=" + bottom +
'}';
}

public TabValue() {
}
public RectF valueToRect(){
return new RectF(left,top,right,bottom);
}

@Override
public String toString() {
return "TabValue{" +
"left=" + left +
", right=" + right +
'}';
}
}
public TabValue rectToValue(RectF rectF){
left = rectF.left;
top = rectF.top;
right = rectF.right;
bottom = rectF.bottom;
return this;
}
}
Loading

0 comments on commit a451ebc

Please sign in to comment.