如何在布局边缘放置一个按钮

How can I place a button on the edge of layout

如何将按钮放置在布局的边缘。一半按钮应该在不同的布局上,一半在不同的布局上。

一种解决方案是提供负边距,但此解决方案不适用于我的布局。

下图是导航按钮,我希望按钮的位置完全相同。和

你能检查一下这是否有效吗?

android:layout_alignParentTop="true"

我将它添加到我的代码中并且它可以工作但是没有你的代码我无法告诉你这是否正确

如果你想给你的 BarLayout 添加一个按钮,我认为代码是不同的。

您可以使用 app:layout_anchorapp:layout_anchorGravity 属性来做到这一点:

例如使用此代码,

<ImageButton
    android:id="@+id/myImageButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email"
    app:layout_anchor="@id/toolbar_layout"
    app:layout_anchorGravity="bottom|left|end" 
    />

您将 myImageButton 锚定在 toolbar_layout 的左下角。