当前位置: 首页 > news >正文

安卓流式布局实现记录

效果图:

1、导入第三方控件

    implementation 'com.google.android:flexbox:1.1.0'

2、布局中使用

  <com.google.android.flexbox.FlexboxLayoutandroid:id="@+id/baggageFl"android:layout_width="match_parent"android:layout_height="wrap_content"app:flexWrap="wrap"app:justifyContent="space_evenly" ></com.google.android.flexbox.FlexboxLayout>

3、流式布局中内容的填充
这里有两种实现方式:xml中直接写和动态添加view
第一种和正常写布局一样,只要把内容控件写进去就行,就不说了,主要说第二种

举例说明:
创建一个子布局:item_baggage.xml

<?xml version="1.0" encoding="utf-8"?>
<com.hjq.shape.layout.ShapeConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="wrap_content"android:paddingVertical="@dimen/dp_5"android:paddingHorizontal="@dimen/dp_8"xmlns:app="http://schemas.android.com/apk/res-auto"><com.hjq.shape.view.ShapeTextViewandroid:id="@+id/baggageNameTv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="@dimen/dp_10"android:layout_marginEnd="@dimen/dp_10"android:paddingHorizontal="@dimen/dp_15"android:paddingVertical="@dimen/dp_5"android:text="----"android:textColor="#333333"android:textSize="@dimen/sp_16"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintTop_toTopOf="parent"app:shape_radius="@dimen/dp_10"app:shape_solidColor="#66FFD374"app:shape_strokeColor="#FFD374"app:shape_strokeSize="@dimen/dp_1" /><ImageViewandroid:id="@+id/closeImg"android:layout_width="@dimen/dp_20"android:layout_height="@dimen/dp_20"android:src="@mipmap/close_icon"app:layout_constraintBottom_toTopOf="@+id/baggageNameTv"app:layout_constraintEnd_toEndOf="@+id/baggageNameTv"app:layout_constraintStart_toEndOf="@+id/baggageNameTv"app:layout_constraintTop_toTopOf="@+id/baggageNameTv" />
</com.hjq.shape.layout.ShapeConstraintLayout>

  2、动态添加view到FlexboxLayout中

    private fun addLayoutToFlexboxLayout(strList: List<String>) {for (str in strList) {val itemView = LayoutInflater.from(this).inflate(R.layout.item_baggage, null)itemView.findViewById<ShapeTextView>(R.id.baggageNameTv).text = strbinding.baggageFl.addView(itemView)}}

http://www.lryc.cn/news/460355.html

相关文章:

  • -bash gcc command not found解决方案(CentOS操作系统)
  • (二)Python输入输出函数
  • 从调用NCCL到深入NCCL源码
  • 深入理解Transformer的笔记记录(精简版本)NNLM → Word2Vec
  • 优选算法第一讲:双指针模块
  • 智能优化算法-水循环优化算法(WCA)(附源码)
  • 基于SpringBoot的个性化健康建议平台
  • Mapsui绘制WKT的示例
  • Modbus TCP 西门子PLC指令以太口地址配置以及 Poll Slave调试软件地址配置
  • MySQL表的基本查询上
  • MySQL中什么情况下类型转换会导致索引失效
  • 数据治理的意义
  • 快手游戏服务端C++开发一面-面经总结
  • git的学习使用(认识工作区,暂存区,版本区。添加文件的方法)
  • Series数据去重
  • Python语言核心12个必知语法细节
  • 解决ImageIO无法读取部分JPEG格式图片问题
  • 使用three.js 实现蜡烛效果
  • 手动在Linux服务器上部署并运行SpringBoot项目(新手向)
  • 自媒体短视频如何制作?
  • 2024年河南省职业技能竞赛(网络建设与运维赛项)
  • git--git reset
  • Spring Boot的实用内置功能详解
  • 撸猫变梳毛?怎么解决猫咪掉毛问题?好用的宠物空气净化器推荐
  • 人声分离免费软件,六款好用软件处理音乐更轻松!
  • 数据分析Power BI设置万为单位的数据
  • (AI 生成) 新时代游击方式: 利用 “灵活就业“ 红利
  • Unity UndoRedo(撤销重做)功能
  • 28条有关人工智能的名言
  • 搞机器视觉项目看不起搞机器视觉培训的,实际上怎么样