Skip to content

Commit

Permalink
处理 LabelFlowlayout 为固定宽度时,换行有空格的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
LillteZheng committed Mar 29, 2023
1 parent 0714a69 commit 19e48f7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ implementation 'com.github.LillteZheng:FlowHelper:v2.3'


## 版本信息:
- v2.4 : 修复TabLabelLayout 在调用 resetStatus,第一个无法点击的问题。并增加 BaseLabelItem,Bean 类继承它,可实现换行
- 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 加粗不起作用的问题
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public class LabelActivity extends BaseActivity {
private List<String> mTitle = new ArrayList<>(Arrays.asList("新闻", "娱乐", "学习", "测试后", "新闻", "娱乐", "学习"));
private List<String> mTitle2 = new ArrayList<>(Arrays.asList("Life is like an ocean Only strong willed ".split(" ")));

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -32,34 +33,34 @@ protected void onCreate(Bundle savedInstanceState) {
canLongFlow();
}

private void singleFlow(){
private void singleFlow() {
LabelFlowLayout flowLayout = findViewById(R.id.singleflow);
List<SingleBean> datas = new ArrayList();
for (int i = 0; i < mTitle.size(); i++) {
for (int i = 0; i < 20; i++) {
SingleBean bean = new SingleBean();
bean.name = mTitle.get(i);
if (i == 0 || i == 3){
bean.name = "测试 " + i;
if (i == 0 || i == 3 || i == 10) {
bean.isHeader = true;
bean.name = "Header";
}
datas.add(bean);
}
final LabelFlowAdapter adapter;
flowLayout.setAdapter(adapter = new LabelFlowAdapter<SingleBean>(R.layout.item_textview,datas) {
flowLayout.setAdapter(adapter = new LabelFlowAdapter<SingleBean>(R.layout.item_textview, datas) {
@Override
public void bindView(View view, SingleBean data, int position) {
setText(view, R.id.item_text,data.name)
. setTextColor(view, R.id.item_text,getResources().getColor(R.color.unselect));
setText(view, R.id.item_text, data.name)
.setTextColor(view, R.id.item_text, getResources().getColor(R.color.unselect));
}


@Override
public void onItemSelectState(View view, boolean isSelected) {
super.onItemSelectState(view, isSelected);
if (isSelected){
setTextColor(view, R.id.item_text,Color.BLACK);
}else{
setTextColor(view, R.id.item_text,getResources().getColor(R.color.unselect));
if (isSelected) {
setTextColor(view, R.id.item_text, Color.BLACK);
} else {
setTextColor(view, R.id.item_text, getResources().getColor(R.color.unselect));
}
}
});
Expand All @@ -73,94 +74,93 @@ public void onClick(View view) {
}
});

// flowLayout.setSelects(6);
// flowLayout.setSelects(6);

}

class SingleBean extends BaseLabelItem{
class SingleBean extends BaseLabelItem {
public String name;
}

private void searchFlow(){
private void searchFlow() {
LabelFlowLayout flowLayout = findViewById(R.id.search_flow);
flowLayout.setAdapter(new LabelFlowAdapter<String>(R.layout.item_textview,mTitle) {
flowLayout.setAdapter(new LabelFlowAdapter<String>(R.layout.item_textview, mTitle) {
@Override
public void bindView(View view, String data, int position) {
setText(view, R.id.item_text,data)
.setTextColor(view, R.id.item_text,Color.WHITE);
setText(view, R.id.item_text, data)
.setTextColor(view, R.id.item_text, Color.WHITE);
view.setBackground(CommonUtils.getColorDrawable(10));
}
});

}

private void multiFlow(){
private void multiFlow() {
LabelFlowLayout flowLayout = findViewById(R.id.multiflow);
flowLayout.setMaxSelectCount(3);
flowLayout.setAdapter(new LabelFlowAdapter<String>(R.layout.item_textview,mTitle2) {
flowLayout.setAdapter(new LabelFlowAdapter<String>(R.layout.item_textview, mTitle2) {
@Override
public void bindView(View view, String data, int position) {
setText(view, R.id.item_text,data);
setText(view, R.id.item_text, data);
}



@Override
public void onReachMaxCount(List<Integer> ids, int count) {
super.onReachMaxCount(ids, count);
Toast.makeText(LabelActivity.this, "最多只能选中 "+count+" 个"+" 已选中坐标: "+ids, Toast.LENGTH_SHORT).show();
Toast.makeText(LabelActivity.this, "最多只能选中 " + count + " 个" + " 已选中坐标: " + ids, Toast.LENGTH_SHORT).show();
}


});

//选中默认数据
flowLayout.setSelects(2,3,5);
flowLayout.setSelects(2, 3, 5);

}

private void canLongFlow(){
private void canLongFlow() {
LabelFlowLayout flowLayout = findViewById(R.id.longflow);
flowLayout.setAdapter(new LabelFlowAdapter<String>(R.layout.item_search_layout,mTitle2) {
flowLayout.setAdapter(new LabelFlowAdapter<String>(R.layout.item_search_layout, mTitle2) {
@Override
public void bindView(View view, String data, int position) {
setText(view, R.id.search_msg_tv,data)
.addChildrenClick(view, R.id.search_delete_iv,position);
setText(view, R.id.search_msg_tv, data)
.addChildrenClick(view, R.id.search_delete_iv, position);
}

@Override
public void onItemSelectState(View view, boolean isSelected) {
super.onItemSelectState(view, isSelected);
if (!isSelected){
if (!isSelected) {
view.setBackgroundResource(R.drawable.shape_search);
setVisible(view, R.id.search_delete_iv,false);
setVisible(view, R.id.search_delete_iv, false);
}
}

@Override
public void onItemClick(View view, String data, int position) {
super.onItemClick(view, data, position);
Toast.makeText(LabelActivity.this, "点击了: "+data, Toast.LENGTH_SHORT).show();
Toast.makeText(LabelActivity.this, "点击了: " + data, Toast.LENGTH_SHORT).show();
}

@Override
public void onItemChildClick(View childView, int position) {
super.onItemChildClick(childView, position);
if (childView.getId() == R.id.search_delete_iv){
if (childView.getId() == R.id.search_delete_iv) {
mTitle2.remove(position);
notifyDataChanged();
}
}

@Override
public boolean onItemLongClick(View view,int position) {
public boolean onItemLongClick(View view, int position) {
/**
* 置所有view 的 select 为 false
*/
resetStatus();
view.setBackgroundResource(R.drawable.shape_search_select);
setVisible(view, R.id.search_delete_iv,true);
return super.onItemLongClick(view,position);
setVisible(view, R.id.search_delete_iv, true);
return super.onItemLongClick(view, position);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ private void measureVertical(int widthMeasureSpec, int heightMeasureSpec) {
mLineHeights.add(lineHeight);
mAllViews.add(lineViews);
lineViews = new ArrayList<>();
//重置为下一个child 的宽度
lineWidth = 0;
lineHeight = 0;
}
}
lineWidth += cWidth;
Expand All @@ -320,11 +323,12 @@ private void measureVertical(int widthMeasureSpec, int heightMeasureSpec) {
if (isHeader) {
//换行
height += lineHeight;


mLineHeights.add(lineHeight);
mAllViews.add(lineViews);
lineViews = new ArrayList<>();
//重置为下一个child 的宽度
lineWidth = 0;
lineHeight = 0;
}


Expand Down

0 comments on commit 19e48f7

Please sign in to comment.