【Android】FlexboxLayout实践
来源:互联网 发布:搞笑网络剧 编辑:程序博客网 时间:2024/06/07 08:36
1.添加依赖
compile 'com.google.android:flexbox:0.2.6'
2.布局
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.naton.materialdemo.FlexLayoutActivity"> <com.google.android.flexbox.FlexboxLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/flexbox_layout" app:flexWrap="wrap" app:alignItems="center" app:alignContent="flex_start" app:flexDirection="row" app:justifyContent="flex_start" app:showDivider="beginning|middle" > </com.google.android.flexbox.FlexboxLayout></android.support.constraint.ConstraintLayout>
3.代码部分
package com.naton.materialdemo;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.Gravity;import android.view.ViewGroup;import android.widget.TextView;import com.google.android.flexbox.FlexboxLayout;public class FlexLayoutActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_flex_layout); FlexboxLayout mFlexboxLayout = (FlexboxLayout) findViewById(R.id.flexbox_layout); // 通过代码向FlexboxLayout添加View for (int i = 5;i<20;i++){ TextView textView = new TextView(this); //textView.setBackgroundDrawable(getResources().getDrawable(R.drawable.progressbar_refresh)); textView.setText(i+"Label"); textView.setGravity(Gravity.CENTER); textView.setPadding(30,0,30,0); textView.setTextColor(getResources().getColor(R.color.text_color)); mFlexboxLayout.addView(textView); //通过FlexboxLayout.LayoutParams 设置子元素支持的属性 /*ViewGroup.LayoutParams params = textView.getLayoutParams(); if(params instanceof FlexboxLayout.LayoutParams){ FlexboxLayout.LayoutParams layoutParams = (FlexboxLayout.LayoutParams) params; layoutParams.setLayoutDirection(5); }*/ } }
}
效果图:
阅读全文
0 0
- 【Android】FlexboxLayout实践
- Android FlexboxLayout
- Android FlexboxLayout基本用法
- Android中的FlexboxLayout
- Android FlexboxLayout 简单介绍
- android中使用flexboxlayout
- Android最新控件FlexboxLayout
- android flexboxlayout简单使用
- Android中的FlexboxLayout
- Android FlexboxLayout使用体验
- Android布局-FlexboxLayout
- android布局-FlexboxLayout
- 流失布局Android FlexboxLayout
- Android FlexboxLayout UI布局
- Android Flexboxlayout使用详解
- FlexboxLayout-----Android弹性布局
- Android FlexBoxLayout 详解
- FlexboxLayout
- ListView和RecyclerView点击返回顶部
- AJAX方法介绍
- iOS字符串拼接 stringByAppendingString:与 stringByAppendingPathComponent:
- 深入理解Tomcat虚拟目录
- com.mchange.v2.c3p0.ComboPooledDataSource
- 【Android】FlexboxLayout实践
- MAC常用命令
- css
- [FAQ20469]The Exif Makernote
- Android对apk源码的修改--反编译+源码修改+重新打包+签名【附HelloWorld的修改实例】
- HTML DOM和BOM常用操作总结
- Linux中xdg-open命令的用法
- win批处理文件--学习笔记
- 来自西弗吉利亚大学li xin整理的CV代码合集