gpt4 book ai didi

android - 线性布局 :How to fill the whole width of screen?

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

我有以下布局文件,它在相关布局内创建线性布局。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#eeeeee">

<LinearLayout // I want this to fill the whole width of screen.
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="50px"
android:background="#666666"


>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/newEvent"
android:hint="Enter the Name of Event"
android:layout_below="@+id/textView2"
android:layout_alignParentStart="true" />


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Location"
android:id="@+id/pickerButton"
android:layout_alignTop="@+id/newEvent"
android:layout_toEndOf="@+id/newEvent" />



</LinearLayout>

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Remainder"
android:id="@+id/submit"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View All"
android:id="@+id/view"
android:layout_below="@+id/submit"
android:layout_centerHorizontal="true"
android:layout_marginTop="68dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Location Will Appear Here"
android:id="@+id/textView4"

android:layout_above="@+id/submit"
android:layout_centerHorizontal="true"
android:layout_marginBottom="48dp" />

</RelativeLayout>

使用这段代码,我得到了以下布局:

enter image description here

但是在灰色的左边、右边和顶部留有空格(线性布局)。我不想要这些空间。我想用灰色填充整个宽度。我应该在我的 xml 中进行哪些更改才能实现此目的?

提前致谢!

编辑:

感谢您的回答。但是在解决这个问题之后,我在灰色框的底部得到了我的文本框和按钮,如下图所示:

enter image description here

为此,我已经尝试过 "android:gravity="center_horizo​​ntal""android:gravity="center_vertical""android:gravity ="center"。我也尝试过 padding-bottom

但这行不通。

最佳答案

移除

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"

来自父 RelativeLayout 的行

<LinearLayout            
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="50px"
android:background="#666666"
android:orientation="horizontal"
android:gravity="center_vertical"
>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/newEvent"
android:hint="Enter the Name of Event"
android:layout_gravity="center_vertical" />


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Location"
android:id="@+id/pickerButton"
android:layout_gravity="center_vertical" />



</LinearLayout>

关于android - 线性布局 :How to fill the whole width of screen?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38900772/

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