流式布局(最近搜索)简单使用

1.依赖

//流式布局
    api 'com.hyman:flowlayout-lib:1.1.2'

2.布局

<TextView
        android:id="@+id/zuijin_sousuo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="最近搜索"
        android:textSize="@dimen/dp_14"
        android:textColor="#6666"
        />

    <com.zhy.view.flowlayout.TagFlowLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/flowlayout"
        android:is_limit ="true"  true表示限制隐藏,false表示不限制行数
		android:limit_line_count="3" 表示最大展示行,这里设置展示3行
        />

tv.xml

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="@dimen/sp_17"
    android:layout_marginLeft="@dimen/dp_10"
    android:id="@+id/text_liu"
    />

3.activity

  flowLayout = findViewById(R.id.flowlayout);//布局
  find_find_find = findViewById(R.id.find_find_find);//搜索按钮
  
 //点击搜索
 private LayoutInflater from;
 private List<String> list = new ArrayList<>();
 ------------handler线程---------------
 @SuppressLint("HandlerLeak")
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
        //设置流式布局adapter,【添加<String>(list)和更改Object为String】。
            flowLayout.setAdapter(new TagAdapter<String>(list) {
                @Override
                public View getView(FlowLayout parent, int position, String o) {
                    TextView textView = (TextView) from.inflate(R.layout.tv,flowLayout,false);
                    textView.setText(o);
                    return textView;
                }
            });
        }
    };
    
from = LayoutInflater.from(this);//流式布局

        find_find_find.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                list.add(s);//集合---s代表输入框输入的字
                handler.sendEmptyMessageDelayed(1,0);//线程发送消息
            }
        });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值