如何使 android View 的宽度和高度为父 View 的一半?像这里加星标的部分:
+-------|-------+
|*******| |
|*******| |
|*******| |
|*******| |
|*******| |
|*******| |
|-------|-------|
| | |
| | |
| | |
| | |
| | |
| | |
+-------|-------+
编辑
阅读此问题的任何人,您最好使用 AppCompat GridLayout
并使用 column_weight
,如 here 所述因为嵌套权重很昂贵。
最佳答案
一些虚假的布局和布局权重一定可以解决问题..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#FFFFFF"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="@+id/dummy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:id="@+id/dummy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
<LinearLayout
android:id="@+id/dummy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
关于android - 查看其父级高度和宽度的一半,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26369237/