简体   繁体   English

为什么在线性布局中指定按钮之间的间距不起作用?

[英]why specifying space between buttons in linear layout doesn't work?

I want some space between two buttons in my layout, but for some reason, my xml doesn't seem to work. 我想在布局中的两个按钮之间留一些空间,但是由于某种原因,我的xml似乎不起作用。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_alignParentBottom="true"
    >

    <Button
        android:id="@+id/btnAnswer_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/T1_Ans1"
        android:layout_margin="2dp"
        android:background="@color/answerRed"
        android:textColor="@color/textColor"
        android:textStyle="bold"
        />

    <Button
        android:id="@+id/btnAnswer_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/T1_Ans2"
        android:layout_margin="2dp"
        android:background="@color/answerBlue"
        android:textColor="@color/textColor"
        android:textStyle="bold"
        android:layout_marginTop="50dp"/>
</LinearLayout>

The result looks like this: 结果看起来像这样:

在此处输入图片说明

Try this :-- 尝试这个 : -

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_alignParentBottom="true"
    >
<Button
    android:id="@+id/btnAnswer_1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="@string/T1_Ans1"
    android:layout_margin="2dp"
    android:background="@color/answerRed"
    android:textColor="@color/textColor"
    android:textStyle="bold"
    />

<Button
    android:id="@+id/btnAnswer_2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="@string/T1_Ans2"
    android:background="@color/answerBlue"
    android:textColor="@color/textColor"
    android:textStyle="bold"
    android:layout_marginTop="50dp"/>
</LinearLayout>

try this 尝试这个

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_alignParentBottom="true"
>

    <Button
        android:id="@+id/btnAnswer_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/T1_Ans1"
        android:layout_margin="2dp"
        android:background="@color/answerRed"
        android:textColor="@color/textColor"
        android:textStyle="bold"
    />

    <Button
        android:id="@+id/btnAnswer_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/T1_Ans2"
        android:background="@color/answerBlue"
        android:textColor="@color/textColor"
        android:textStyle="bold"
        android:layout_marginTop="50dp"/>
</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM