gpt4 book ai didi

android - XML 布局中忽略了按钮填充属性

转载 作者:行者123 更新时间:2023-11-29 14:27:51 27 4
gpt4 key购买 nike

我正在尝试在屏幕上以 2x3(w/h)的形式设置 6 个按钮的布局。

我的布局 XML 如下:

<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"
android:background="@drawable/androidbg"
android:paddingBottom="@dimen/none"
android:paddingLeft="@dimen/none"
android:paddingRight="@dimen/none"
android:paddingTop="@dimen/none"
tools:context=".MainActivity" >

<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >

<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="4dip"
android:orientation="horizontal" >

<Button
android:id="@+id/btnTopLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/diary"
android:layout_weight="1"
android:background="@drawable/menu_button"
style="?android:attr/buttonBarButtonStyle"
android:onClick="openDiary"
android:padding="4dip" />

<Button
android:id="@+id/btnTopRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/diary"
android:layout_weight="1"
android:background="@drawable/menu_button"
style="?android:attr/buttonBarButtonStyle"
android:onClick="openDiary"
android:padding="4dip" />
</LinearLayout>
</RelativeLayout>

<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="4dip"
android:orientation="horizontal" >

<Button
android:id="@+id/btnMidLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/diary"
android:layout_weight="1"
android:background="@drawable/menu_button"
style="?android:attr/buttonBarButtonStyle"
android:onClick="openDiary"
android:padding="4dip" />

<Button
android:id="@+id/btnMidRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/diary"
android:layout_weight="1"
android:background="@drawable/menu_button"
style="?android:attr/buttonBarButtonStyle"
android:onClick="openDiary"
android:padding="4dip" />
</LinearLayout>
</RelativeLayout>

<RelativeLayout
android:id="@+id/relativeLayout3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="4dip"
android:orientation="horizontal" >

<Button
android:id="@+id/btnBottomLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/diary"
android:layout_weight="1"
android:background="@drawable/menu_button"
style="?android:attr/buttonBarButtonStyle"
android:onClick="openDiary"
android:padding="4dip" />

<Button
android:id="@+id/btnBottomRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/diary"
android:layout_weight="1"
android:background="@drawable/menu_button"
style="?android:attr/buttonBarButtonStyle"
android:onClick="openDiary"
android:padding="4dip" />
</LinearLayout>
</RelativeLayout>

</LinearLayout>

此 XML 主要按我希望的方式工作 - 除了 android:padding="4dip"<Button>里面标签。此填充似乎被完全忽略,使按钮在中间被压扁。

下面我提供了一个粗略的绘图(看我的绘画技巧),左边是应用程序的当前状态,右边是应用程序的预期布局(蓝色框是按钮)。

Current vs Intended layout

有什么想法可以让中间的按钮分开吗?

最佳答案

您必须添加 margin 而不是 padding,这取决于您必须在何处应用边距(layout_marginLeft layout_marginRight) 但这应该可以解决您的问题:

android:layout_margin="4dp"

代替

android:padding="4dp"

关于android - XML 布局中忽略了按钮填充属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17472907/

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