android xml正方形,使用Android Constraintlayout创建一排均匀分布的正方形

我正在努力创建一个由均匀分布的正方形链组成的布局,这些正方形可以填充可用空间。使用Android Constraintlayout创建一排均匀分布的正方形

我到底想要的布局,看起来像这样:

YQAoJ.png

的想法是,与不同的宽高比手机这个正方形成长一点点地使用了额外的空间。

我设法创建权重链与此布局

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/activity_main_inference"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/textView1"

android:layout_width="32dp"

android:layout_height="0dp"

android:text="All"

app:layout_constraintDimensionRatio="w,1:1"

app:layout_constraintHorizontal_weight="1"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toLeftOf="@+id/textView2"

app:layout_constraintTop_toTopOf="parent" />

android:id="@+id/textView2"

android:layout_width="32dp"

android:layout_height="0dp"

android:text="2"

app:layout_constraintDimensionRatio="w,1:1"

app:layout_constraintHorizontal_weight="1"

app:layout_constraintLeft_toRightOf="@+id/textView1"

app:layout_constraintRight_toLeftOf="@id/textView4"/>

android:id="@+id/textView4"

android:layout_width="32dp"

android:layout_height="0dp"

android:text="4"

app:layout_constraintDimensionRatio="w,1:1"

app:layout_constraintHorizontal_weight="1"

app:layout_constraintLeft_toRightOf="@+id/textView2"

app:layout_constraintRight_toRightOf="parent" />

这看起来是这样的:

dfb0b71b9c3173be2329abfed3e2d386.png

这是罚款只是Textviews的宽度是固定到32dp。 我希望,如果我将宽度也设置为零,匹配约束将首先确定所需的宽度以覆盖所有空间,然后将高度设置为宽度以使视图平方。

可悲的是我的布局是这样的:

873359829296d5dba3800b8502e22288.png

是这种想法,我想ContraintLayout实现可能布局的?

2017-08-14

Janusz

+0

你想这种类型的视图https://i.stack.imgur.com/YQAoJ.png? –

+0

是的,这是我想要实现的。 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值