Android流式布局实现历史搜索记录功能

  

最近在开发项目的时候,有一个需求是展示历史搜索记录,展示的样式是流式布局(就是根据内容自动换行)。在网上看到了一个不错的类库跟大家分享一下

  

首先在AndroidStudio简历一个工程项目导入模块类库,我会把项目演示方法GitHub上

  

说一下演示中的实现方式

  

在activity_main.xml中         & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android "   xmlns:应用=" http://schemas.android.com/apk/res-auto "   xmlns:工具=" http://schemas.android.com/tools "   android: id=癅 + id/activity_main”   android: layout_width=" match_parent "   android: layout_height=" match_parent "   面向android:=按怪薄北?   EditText & lt;   android: id=癅 + id/美国”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "/比;   & lt;按钮   android: id=癅 + id/btn”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android:文本="确定”/比;   & lt;滚动视图   android: layout_width=" match_parent "   android: layout_height=癿atch_parent”比;   & lt; com.zhy.view.flowlayout.TagFlowLayout   android: id=癅 + id/id_flowlayout”   android: layout_width="宽和"   android: layout_height=" wrap_content "   应用:max_select=" 1 "/比;   & lt;/ScrollView>   & lt;/LinearLayout>      

实现模拟搜索效果图

  

 Android流式布局实现历史搜索记录功能

  

MainActivity。Java代码

        公开课MainActivity延伸AppCompatActivity {   私人TagFlowLayout mFlowLayout;   私人EditText EditText;   私人按钮按钮;   私人List字符串;//布局管理器   私人LayoutInflater mInflater;//流式布局的子布的局   私人TextView电视;   公共处理程序处理程序=new处理程序(){   @Override   公共空间handleMessage(消息味精){   开关(msg.what) {   案例1:   mFlowLayout。setAdapter(新TagAdapter(字符串){   @Override   公众视线getView (FlowLayout父,int位置,字符串s) {   电视=(TextView) mInflater.inflate (R.layout.tv   mFlowLayout、假);   tv.setText(年代);   返回电视;   }   });   打破;   }   super.handleMessage(味精);   }   };   @Override   保护无效alt=" Android流式布局实现历史搜索记录功能">

  

这样就实现了一个简单的流式布局历史搜索记录

  

GitHub地址:https://github.com/zhangliyong114/FlowLayoutDemo

  

以上所述是小编给大家介绍的Android流式布局实现历史搜索记录功能,希望对大家有所帮助,如果大家有任何疑问请给我留的言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

Android流式布局实现历史搜索记录功能