当前位置:网站首页>Constrained layout flow
Constrained layout flow
2022-07-05 10:11:00 【A bird carved in the desert】
Flow Fluid layout
There are many ways to implement streaming layout , such as RecycleView Of StaggeredGridLayoutManager, perhaps Customize the dynamic calculation method of layout etc. , No matter which implementation , Are all behind ConstraintLayout Provided Flow Fluid layout More flexible , It's simpler .
base_component_learn/ConstraintFlowActivity.java at master · buder-cp/base_component_learn · GitHub
Here we add dynamically , The effect is as follows :

The code is very simple , That is, you can use dynamic add layout :
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.helper.widget.Flow;
import androidx.constraintlayout.widget.ConstraintLayout;
import java.util.ArrayList;
public class ConstraintFlowActivity extends AppCompatActivity {
private ConstraintLayout mainLayout;
private Flow flow;
private int[] idsss = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
private String[] strings = new String[]{ " It's amazing how dark the silver man is... How dark the silver man is ", " Freely flowing style of writing ", " tearful ", " Good words ",
" Frost ", " Cuitong, cuitong ", " beam with joy ", " Maggie ", " Rong ", " Words describing friendship ",
" A collection of beautiful words ", " smile into each other 's eyes ", " Smile ", " Esteem, ", " look very happy ", " Charming ", " The darkness at ", " Day and night, day and night ", " It wins, ", "ads"};
private ArrayList<Integer> arrayList = new ArrayList<Integer>();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.constraint_exercise);
mainLayout = (ConstraintLayout) LayoutInflater.from(this).inflate(R.layout.constraint_exercise, null);
setContentView(mainLayout);
for (int i = 1; i < 20; i++) {
arrayList.add(i);
mainLayout.addView(generateView(i));
}
flow = findViewById(R.id.constrain_flows);
// flow.setMaxElementsWrap(3);
// flow.setHorizontalAlign();
flow.setWrapMode(1);
flow.setReferencedIds(idsss);
}
private TextView generateView(int i) {
TextView textView = new TextView(getApplicationContext());
textView.setId(i);
textView.setPadding(12, 5, 12, 5);
textView.setTextColor(Color.BLACK);
textView.setBackgroundResource(R.drawable.vip_course_selector_bg);
textView.setText(strings[i]);
return textView;
}
}XML The code contains only one flow that will do :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.helper.widget.Flow
android:id="@+id/constrain_flows"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="20dp"
app:layout_constraintTop_toTopOf="parent"
app:flow_horizontalGap="10dp"
app:flow_verticalGap="10dp"
app:flow_maxElementsWrap="4"
app:flow_wrapMode="aligned" />
</androidx.constraintlayout.widget.ConstraintLayout>Write in native code flow Is streaming layout very simple .
Specifically Flow You can see some specific properties of ConstraintLayout 2.0 Analysis of new features ( One )--Flow Fluid layout - Simple books
The core is to use attributes :app:constraint_referenced_ids take 7 individual ImageView Restrain yourself .
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.helper.widget.Flow
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:flow_horizontalGap="10dp"
app:flow_verticalGap="10dp"
app:flow_wrapMode="none"
app:constraint_referenced_ids="image1,image2,image3,image4,image5,image6,image7" />
<ImageView
android:id="@+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/image3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/image4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/image5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/image6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/image7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
</androidx.constraintlayout.widget.ConstraintLayout>边栏推荐
- Comparison of batch merge between Oracle and MySQL
- 如何写出高质量的代码?
- Z-blog template installation and use tutorial
- Why don't you recommend using products like mongodb to replace time series databases?
- Android SQLite database encryption
- Apache DolphinScheduler 系统架构设计
- 如何判断线程池已经执行完所有任务了?
- Kotlin Compose 与原生 嵌套使用
- Unity粒子特效系列-毒液喷射预制体做好了,unitypackage包直接用 - 上
- 硬核,你见过机器人玩“密室逃脱”吗?(附代码)
猜你喜欢

剪掉ImageNet 20%数据量,模型性能不下降!Meta斯坦福等提出新方法,用知识蒸馏给数据集瘦身...

【系统设计】指标监控和告警系统

Wechat applet - simple diet recommendation (2)

StaticLayout的使用详解

一种用于干式脑电图的高密度256通道电极帽

Unity particle special effects series - the poison spray preform is ready, and the unitypackage package is directly used - on

Design and exploration of Baidu comment Center
![[tips] get the x-axis and y-axis values of cdfplot function in MATLAB](/img/08/2d039df6ea3ace8685512b2af8281d.png)
[tips] get the x-axis and y-axis values of cdfplot function in MATLAB

Cross process communication Aidl

Apache DolphinScheduler 入门(一篇就够了)
随机推荐
LiveData 面试题库、解答---LiveData 面试 7 连问~
MySQL digital type learning notes
Cross process communication Aidl
Apache DolphinScheduler 系统架构设计
oracle和mysql批量Merge对比
如何獲取GC(垃圾回收器)的STW(暫停)時間?
剪掉ImageNet 20%数据量,模型性能不下降!Meta斯坦福等提出新方法,用知识蒸馏给数据集瘦身...
Apache dolphin scheduler system architecture design
让AI替企业做复杂决策真的靠谱吗?参与直播,斯坦福博士来分享他的选择|量子位·视点...
QT realizes signal transmission and reception between two windows
Is it really reliable for AI to make complex decisions for enterprises? Participate in the live broadcast, Dr. Stanford to share his choice | qubit · viewpoint
From "chemist" to developer, from Oracle to tdengine, two important choices in my life
The Alipay in place function can't be found, and the Alipay in place function is offline
Mobile heterogeneous computing technology GPU OpenCL programming (Advanced)
The comparison of every() and some() in JS uses a power storage plan
Analysis on the wallet system architecture of Baidu trading platform
Hard core, have you ever seen robots play "escape from the secret room"? (code attached)
【小技巧】获取matlab中cdfplot函数的x轴,y轴的数值
钉钉、企微、飞书学会赚钱了吗?
Six simple cases of QT