android xml正方形,使用Android Constraintlayout创建一排均匀分布的正方形
我正在努力創(chuàng)建一個由均勻分布的正方形鏈組成的布局,這些正方形可以填充可用空間。使用Android Constraintlayout創(chuàng)建一排均勻分布的正方形
我到底想要的布局,看起來像這樣:
的想法是,與不同的寬高比手機這個正方形成長一點點地使用了額外的空間。
我設(shè)法創(chuàng)建權(quán)重鏈與此布局
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" />
這看起來是這樣的:
這是罰款只是Textviews的寬度是固定到32dp。 我希望,如果我將寬度也設(shè)置為零,匹配約束將首先確定所需的寬度以覆蓋所有空間,然后將高度設(shè)置為寬度以使視圖平方。
可悲的是我的布局是這樣的:
是這種想法,我想ContraintLayout實現(xiàn)可能布局的?
2017-08-14
Janusz
+0
你想這種類型的視圖https://i.stack.imgur.com/YQAoJ.png? –
+0
是的,這是我想要實現(xiàn)的。 –
總結(jié)
以上是生活随笔為你收集整理的android xml正方形,使用Android Constraintlayout创建一排均匀分布的正方形的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机桌面文件自动备份取消,电脑如何取消
- 下一篇: R8500梅林固件