FlexboxLayout是库项目带来的类似功能的 CSS弹性框布局模块到Android。
添加下面的依赖关系到你的build.gradle文件中:
dependencies {
compile 'com.google.android:flexbox:0.2.5'
}
FlexboxLayout扩展了ViewGroup,如LinearLayout和RelativeLayout。您可以从布局XML中指定属性,如:
< com .google.android.flexbox.FlexboxLayout
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 "
app : flexWrap = " wrap "
app : alignItems = " stretch "
app : alignContent = " stretch " >
< TextView
android : id = " @+id/textview1 "
android : layout_width = " 120dp "
android : layout_height = " 80dp "
app : layout_flexBasisPercent = " 50% "
/>
< TextView
android : id = " @+id/textview2 "
android : layout_width = " 80dp "
android : layout_height = " 80dp "
app : layout_alignSelf = " center "
/>
< TextView
android : id = " @+id/textview3 "
android : layout_width = " 160dp "
android : layout_height = " 80dp "
app : layout_alignSelf = " flex_end "
/>
</ com .google.android.flexbox.FlexboxLayout>
或从代码如:
FlexboxLayout flexboxLayout = ( FlexboxLayout ) findViewById( R . id . flexbox_layout);
flexboxLayout . setFlexDirection( FlexboxLayout . FLEX_DIRECTION_COLUMN ); View view = flexboxLayout . getChildAt( 0 );
FlexboxLayout . LayoutParams lp = ( FlexboxLayout . LayoutParams ) view . getLayoutParams();
lp . order = - 1 ;
lp . flexGrow = 2 ;
view . setLayoutParams(lp);
flexDirection
此属性确定主轴(和横轴,垂直于主轴)的方向。子项目放置在Flexbox布局内的方向。可能的值有:

flexWrap
此属性控制flex容器是单行还是多行,以及横轴的方向。可能的值有:

justifyContent
此属性控制沿主轴的对齐。可能的值有:

alignItems
此属性控制沿横轴的对齐。可能的值有:

alignContent
此属性控制flex容器中的flex线的对齐。可能的值有:

showDividerHorizontal(一个或多个none | beginning | middle | end)
dividerDrawableHorizontal(参照绘)
column或column_rebase)。
showDividerVertical(一个或多个none | beginning | middle | end)
dividerDrawableVertical(参照绘)
column或column_rebase)。
showDivider(一个或多个none | beginning | middle | end)
dividerDrawable(参照绘)
justifyContent="space_around"或alignContent="space_between"...等),用于将弯曲线或柔性项目之间的空间,你可能会看到意想不到的空间。请避免同时使用这些。放置垂直和水平分隔线的示例。
res/drawable/divider.xml
< shape xmlns : android = " http://schemas.android.com/apk/res/android " >
< size
android : width = " 8dp "
android : height = " 12dp " />
< solid android : color = " # 44A444 " />
</ shape >
res/layout/content_main.xml
< com .google.android.flexbox.FlexboxLayout 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 "
app : alignContent = " flex_start "
app : alignItems = " flex_start "
app : flexWrap = " wrap "
app : showDivider = " beginning|middle "
app : dividerDrawable = " @drawable/divider " >
< TextView
style = " @style/FlexItem "
android : layout_width = " 220dp "
android : layout_height = " 80dp "
android : text = " 1 " />
< TextView
style = " @style/FlexItem "
android : layout_width = " 120dp "
android : layout_height = " 80dp "
android : text = " 2 " />
< TextView
style = " @style/FlexItem "
android : layout_width = " 160dp "
android : layout_height = " 80dp "
android : text = " 3 " />
< TextView
style = " @style/FlexItem "
android : layout_width = " 80dp "
android : layout_height = " 80dp "
android : text =
本站资源仅限于学习研究,严禁从事商业或者非法活动!
源码搜藏网所有源码来自互联网转载与用户上传分享,如果侵犯了您的权益请与我们联系,我们将在24小时内删除!谢谢!
Android 网格分页布局PagerLayoutManager
Android开发通用圆角布局
适用于拖拽、动画、模糊等效果的UI库
Android多功能的标签流布局
一个包括拖拽、滚动、动画、背景模糊功能的安卓UI布局
Android TabLayout Lib的3种TabLayout
安卓Flexbox的布局
Android流式布局,支持单选、多选等,适合用于产品标签等。
Android屏幕适配方案,直接填写设计图上的像素尺寸即可完成适配
Android开发Google百分比布局库的扩展
Android高仿熊猫TV直播app UI
Android仿360底部菜单布局
Android 网格分页布局PagerLayoutManager
Android开发通用圆角布局
Android多功能的标签流布局
一个包括拖拽、滚动、动画、背景模糊功能的安卓UI布局
Android流式布局,支持单选、多选等,适合用于产品标签等。
Android开发Google百分比布局库的扩展
热门源码