当前位置:网站首页>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>边栏推荐
- Android SQLite database encryption
- Swift set pickerview to white on black background
- TDengine × Intel edge insight software package accelerates the digital transformation of traditional industries
- 【系统设计】指标监控和告警系统
- Tdengine already supports the industrial Intel edge insight package
- Cent7 Oracle database installation error
- Wechat applet - simple diet recommendation (4)
- Fluent development: setting method of left and right alignment of child controls in row
- Implementation of smart home project
- 一个程序员的职业生涯到底该怎么规划?
猜你喜欢

Getting started with Apache dolphin scheduler (one article is enough)

如何獲取GC(垃圾回收器)的STW(暫停)時間?

B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条...

如何判断线程池已经执行完所有任务了?

Meitu lost 300 million yuan in currency speculation for half a year. Huawei was exposed to expand its enrollment in Russia. Alphago's peers have made another breakthrough in chess. Today, more big new

一个程序员的职业生涯到底该怎么规划?

H. 265 introduction to coding principles

Why don't you recommend using products like mongodb to replace time series databases?

【小技巧】獲取matlab中cdfplot函數的x軸,y軸的數值

Unity particle special effects series - the poison spray preform is ready, and the unitypackage package can be used directly - next
随机推荐
Pagoda panel MySQL cannot be started
How to use sqlcipher tool to decrypt encrypted database under Windows system
Analysis on the wallet system architecture of Baidu trading platform
How Windows bat script automatically executes sqlcipher command
Applet image height adaptation and setting text line height
最全是一次I2C总结
H. 265 introduction to coding principles
TypeError: Cannot read properties of undefined (reading ‘cancelToken‘)
Uni app running to wechat development tool cannot Preview
QT event filter simple case
面试:Bitmap像素内存分配在堆内存还是在native中
Those who are good at using soldiers, hide in the invisible, and explain the best promotional value works in depth in 90 minutes
How to get the STW (pause) time of GC (garbage collector)?
Theme. AppCompat. Light. Darkactionbar not found
> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
CSDN always jumps to other positions when editing articles_ CSDN sends articles without moving the mouse
Design and Simulation of fuzzy PID control system for liquid level of double tank (matlab/simulink)
Are databases more popular as they get older?
Implementation of smart home project
@JsonAdapter注解使用