设置 actionLayout 的边距

3
下面是我的actionLayout按钮。基本上,我的actionBar有MenuItems,其中一个项目的actionLayout拥有以下按钮。
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fruit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="15dp"
    android:layout_marginTop="3dp"
    android:background="#999999"
    android:clickable="true"
    android:text="Apple" />

我的问题是按钮的高度一直填充整个父容器。我想设置边距,但是都不起作用。有没有人知道简单的方法来设置边距?


1
你尝试过将按钮放在FrameLayout中吗? - sandrstar
你介意展示一下它会是什么样子吗? - Cote Mounyo
1个回答

4
您可以将按钮包装在FrameLayout中:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="match_parent">
    <Button android:id="@+id/fruit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="50dp"
            android:layout_marginLeft="50dp"
            android:layout_marginTop="3dp"
            android:background="#999999"
            android:clickable="true"
            android:text="Apple" />
</FrameLayout>

And it would look like the following:

device action bar


这个可以运行,但是在边缘空间点击也会触发该操作。 - Dominikus K.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接