gpt4 book ai didi

android - 在 android XML 中使用相对布局

转载 作者:行者123 更新时间:2023-11-29 15:57:11 25 4
gpt4 key购买 nike

我正在尝试按照 http://i.stack.imgur.com/aPoeU.png 的内容在 XML 中创建布局但我对如何以这种格式放置按钮感到困惑。我已经创建了按钮并尝试了不同的东西,如 alignParentBottom、alignParentRight 等,但我似乎无法按照我想要的方式获得它。有人可以帮帮我吗?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Button" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/button1"
android:text="Button" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/button2"
android:text="Button" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/button3"
android:text="Button" />

最佳答案

我们可以通过weight_sum来管理全屏全分辨率

将下面的代码粘贴到您的 xml 中

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000"
android:weightSum="1" >

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:background="#bebebe"
android:layout_weight="0.30"
android:text="Button1" />

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:layout_weight="0.20"
android:background="#bebebe"
android:text="Button2" />

<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:layout_weight="0.20"
android:background="#bebebe"
android:text="Button3" />

<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:layout_weight="0.30"
android:background="#bebebe"
android:text="Button4" />

</LinearLayout>

enter image description here

关于android - 在 android XML 中使用相对布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27387749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com