[英]Android layer-list affecting position of floating action button
我正在創建一個應用程序,其中的圖層列表用作背景,還使用了浮動操作按鈕。 將圖層列表設置為相對布局的背景時,它會更改FAB的位置,但我不明白為什么會發生它。
我希望將FAB放在左下角。 當我沒有將背景設置為圖層列表時,它將顯示在我編碼的位置。
但是,當我將背景屬性添加到“相對”布局時,FAB會自動移入。
我不明白是什么影響了FAB的這種行為。
layer_list的XML:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimary" />
<padding
android:bottom="64dp"
android:left="32dp"
android:right="32dp"
android:top="64dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
<corners
android:bottomLeftRadius="64dp"
android:bottomRightRadius="64dp"
android:topLeftRadius="64dp"
android:topRightRadius="64dp" />
</shape>
</item>
用於活動的XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/home_layer_list">
<TextView
android:id="@+id/text_view"
android:layout_centerInParent="true"
android:textSize="36sp"
android:textStyle="bold"
android:textColor="@color/colorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello world" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="@drawable/ic_fab"
android:layout_margin="16dp"
app:backgroundTint="#FFFFFF"/>
如何使FAB返回到最初的位置?
嘗試如下更改布局:
<RelativeLayout 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/home_layer_list">
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="hello world"
android:textColor="@color/colorPrimary"
android:textSize="36sp"
android:textStyle="bold" />
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:src="@drawable/ic_fab"
android:layout_margin="16dp"
app:backgroundTint="#FFFFFF" />
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.