当使用Linearlayout和3个按钮使用重量时,中间按钮有点低



我有这个布局,在对话框中:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/rView"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_above="@+id/button2"
    android:layout_marginBottom="10dp"/>
<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentBottom="true"
    android:text=""
    android:background="@android:color/transparent"
    android:clickable="false"
    android:enabled="false"/>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:orientation="horizontal"
    android:layout_below="@+id/rView"
    android:weightSum="3">
    <Button
        android:id="@+id/okbutton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/ok"
        android:background="@drawable/buttonshape"
        android:layout_weight="1"
        android:textColor="@color/blanco"/>
    <Button
        android:id="@+id/markall"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/checkall"
        android:background="@drawable/buttonshape"
        android:layout_weight="1"
        android:textColor="@color/blanco"/>
    <Button
        android:id="@+id/cancelbutton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/cancel"
        android:background="@drawable/buttonshape"
        android:layout_weight="1"
        android:textColor="@color/blanco"/>
</LinearLayout>

这是我用作背景的可绘图:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
    android:radius="50dp"
    />
<solid
    android:color="@color/botones"
    />
<stroke
    android:width="0dp"
    android:color="#878787"
    />

在线安装内部有3个按钮,如您所见。他们每个人都应在线性布局中使用相同数量的空间,实际上它们确实可以使用,但是中央按钮(Markall)与其他空间不与其他纽扣对齐,有点低,例如5 dp或类似的东西。我不知道为什么会发生这种情况,以及如何解决。

有帮助吗?

谢谢。

更改按钮宽度" match_parent"。

尝试这个。

android:layout_height="match_parent"设置为Button

并将android:gravity="center"设置为Button文本。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/rView"
    android:orientation="horizontal"
    android:weightSum="3">
    <Button
        android:id="@+id/okbutton"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/buttonshape"
        android:gravity="center"
        android:text="@string/ok"
        android:textColor="@color/blanco"/>
    <Button
        android:id="@+id/markall"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/buttonshape"
        android:gravity="center"
        android:text="@string/checkall"
        android:textColor="@color/blanco"/>
    <Button
        android:id="@+id/cancelbutton"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/buttonshape"
        android:gravity="center"
        android:text="@string/cancel"
        android:textColor="@color/blanco"/>
</LinearLayout>

尝试更改android:layout_height =" match_parent"到" wrap_content",或者每个按钮的高度为" match_parent"

最新更新