【发布时间】:2017-01-21 17:17:26
【问题描述】:
我正在尝试放置 4 个按钮来填充所有相对布局。我希望每个按钮的宽度和高度直到 RelativeLayout 的中心(它们之间大约有 2dp 空间)。我认为我不能解释得很清楚好,所以我制作了一张图片,这是我制作的代码...
有什么想法吗?
谢谢!!
现在的视图是:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textAlignment="center"
android:textSize="30sp"
android:layout_marginTop="10dp"
android:id="@+id/textView" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="@+id/relativeLayout"
android:weightSum="1">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"/>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button4"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
【问题讨论】:
-
试过了吗?到目前为止你做了什么?你现在的布局是什么样的?如果你想要那种布局,我建议使用 Linearlayout。
-
我已经尝试过 layout_weight 但我可以找到任何带有 4 个按钮的解决方案...让我尝试线性布局..
-
使用 Android Studio 提供的工具应该相当容易。给我大概10分钟。我会发布一个答案。除非两个人打我一拳……哈哈……没关系。