当前位置:网站首页>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>
边栏推荐
- To bring Euler's innovation to the world, SUSE should be the guide
- Swift saves an array of class objects with userdefaults and nssecurecoding
- From "chemist" to developer, from Oracle to tdengine, two important choices in my life
- Kotlin Compose 与原生 嵌套使用
- 如何获取GC(垃圾回收器)的STW(暂停)时间?
- H. 265 introduction to coding principles
- Observation cloud and tdengine have reached in-depth cooperation to optimize the cloud experience of enterprises
- .Net之延迟队列
- 卷起來,突破35歲焦慮,動畫演示CPU記錄函數調用過程
- The king of pirated Dall · e? 50000 images per day, crowded hugging face server, and openai ordered to change its name
猜你喜欢
善用兵者,藏于无形,90 分钟深度讲解最佳推广价值作品
How to use sqlcipher tool to decrypt encrypted database under Windows system
Design of stepping motor controller based on single chip microcomputer (forward rotation and reverse rotation indicator gear)
驱动制造业产业升级新思路的领域知识网络,什么来头?
How to implement complex SQL such as distributed database sub query and join?
How Windows bat script automatically executes sqlcipher command
The king of pirated Dall · e? 50000 images per day, crowded hugging face server, and openai ordered to change its name
《微信小程序-基础篇》小程序中的事件与冒泡
[NTIRE 2022]Residual Local Feature Network for Efficient Super-Resolution
(1) Complete the new construction of station in Niagara vykon N4 supervisor 4.8 software
随机推荐
Unity particle special effects series - the poison spray preform is ready, and the unitypackage package can be used directly - next
Fluent development: setting method of left and right alignment of child controls in row
QT VT100 parser
《微信小程序-基础篇》小程序中的事件与冒泡
Click the picture in the mobile browser and the picture will not pop up
Node-RED系列(二九):使用slider与chart节点来实现双折线时间序列图
Apache dolphin scheduler system architecture design
Implementation of smart home project
[system design] index monitoring and alarm system
cent7安装Oracle数据库报错
TypeError: Cannot read properties of undefined (reading ‘cancelToken‘)
CSDN always jumps to other positions when editing articles_ CSDN sends articles without moving the mouse
硬核,你见过机器人玩“密室逃脱”吗?(附代码)
How to get the STW (pause) time of GC (garbage collector)?
Common fault analysis and Countermeasures of using MySQL in go language
驱动制造业产业升级新思路的领域知识网络,什么来头?
卷起来,突破35岁焦虑,动画演示CPU记录函数调用过程
Kotlin compose and native nesting
Swift uses userdefaults and codable to save an array of class objects or structure instances
Theme. AppCompat. Light. Darkactionbar not found