gpt4 book ai didi

android - 一个带有 fab 按钮的 xml 文件

转载 作者:行者123 更新时间:2023-11-29 16:33:13 27 4
gpt4 key购买 nike

我想将另一个包含 fab 按钮的 xml 文件包含到一个 xml 文件中。问题是当我 <include layout="@layout/fab它在屏幕的左上角而不是右下角显示我的 fab 按钮。

这是我的 xml 文件(ConstraintLayout)

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PlanPage.PlanPageView">


<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/activity_fab_button"
android:layout_gravity="end|bottom"/>

</android.support.constraint.ConstraintLayout>

这是 fab 按钮 xml

<android.support.design.widget.FloatingActionButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:src="@drawable/ic_plusphoto_fab"
android:backgroundTint="@color/colorPrimary"
/>

最佳答案

fab xml 中的这个属性:

android:layout_gravity="end|bottom"

在您将布局包含在另一个布局中时无效。
您必须为此布局设置属性:

<include
layout="@layout/activity_fab_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

如果有效。
如果包含布局的宿主布局不是LinearLayout,那么你必须设置其他属性,比如alignParentBottom 用于 RelativeLayout,或者将其约束到 ConstraintLayout 的 Bottom 和 End。

关于android - <Include> 一个带有 fab 按钮的 xml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53570023/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com