首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"android:layout_margin“或"android:layout_marginTop”

"android:layout_margin“或"android:layout_marginTop”
EN

Stack Overflow用户
提问于 2017-12-18 06:03:33
回答 4查看 685关注 0票数 0

我正在写一个屏幕,我想在两个按钮之间放置一个垂直间隙:

代码语言:javascript
复制
 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="@dimen/size40dp"
        android:orientation="vertical">

        <Button
            android:id="@+id/btn_show_cards"
            style="@style/btnStyleAcapulco"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/size50dp"
            android:layout_gravity="center"
            android:text="@string/show_cards" />

        <Button
            android:id="@+id/btn_add_card"
            android:layout_marginTop="@dimen/size40dp"
            style="@style/btnStyleDark_khaki"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/add_card"
            />
    </LinearLayout>

问题是按钮之间没有间隙。但是,当我将"android:layout_marginTop“替换为"android:layout_margin”时,差距就是我想要的。根据我读到的文本,"layout_marginTop“是正确的选项。知道我做了什么吗?

谢谢,

zb

EN

回答 4

Stack Overflow用户

发布于 2017-12-18 07:08:03

根据您的喜好,您可以使用更多关于此scenario.As的答案

从第二个按钮开始1.layout_margin_top="10dp“

从第一个按钮开始2.layout_margin_bottom="10dp“

票数 0
EN

Stack Overflow用户

发布于 2017-12-18 09:04:15

你可以在你的btnStyleAcapulcobtnStyleDark_khaki中使用android:layout_margin="10dp"代码吗?

如果您这样使用,android:layout_marginBottom="40dpandroid:layout_marginTop="40dp将不会对您的布局产生任何影响。

这样你就可以检查了。并像这样删除android:layout_margin="10dp"代码。

first way

1.在按钮btn_show_cards中添加android:layout_marginBottom="40dp""

2.在按钮btn_add_card中添加android:layout_marginTop="40dp"

The second way

您可以在两个按钮之间对代码使用Space

代码语言:javascript
复制
<android.support.v4.widget.Space
    android:layout_width="match_parent"
    android:layout_height="40dp"/>
票数 0
EN

Stack Overflow用户

发布于 2017-12-18 14:11:18

第二个按钮仅声明

代码语言:javascript
复制
android:layout_layout_marginTop=""
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47859905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档