Android xml片段中ListView上方的浮动操作按钮(FAB)?
我使用的代码来自。 在我看来Android xml片段中ListView上方的浮动操作按钮(FAB)?,android,xml,listview,android-fragments,floating-action-button,Android,Xml,Listview,Android Fragments,Floating Action Button,我使用的代码来自。 在我看来 <LinearLayout 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" andr
<LinearLayout
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"
tools:context=".fragments.FragmentList"
android:orientation="vertical"
android:id="@+id/linear">
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView" />
</LinearLayout>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_white_24dp"
android:layout_gravity="bottom|end"
fab:elevation="6dp"
fab:pressedTranslationZ="12dp"
fab:backgroundTint="@color/accent"
app:layout_anchor="@id/listView"/>
</android.support.design.widget.CoordinatorLayout>
但我在Android Studio中有“多个根标签”。我做错了什么?
请帮助我,我无法理解((请改用此布局:
<android.support.design.widget.CoordinatorLayout
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"
tools:context=".fragments.FragmentList"
android:orientation="vertical"
android:id="@+id/linear">
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_white_24dp"
android:layout_gravity="bottom|end"
fab:elevation="6dp"
fab:pressedTranslationZ="12dp"
fab:backgroundTint="@color/accent"
app:layout_anchor="@id/listView"/>
</android.support.design.widget.CoordinatorLayout>
更改这行代码
android:layout_gravity=“bottom | end”
到
android:layout_gravity=“top”
这会将FAB设置为右下。将所有内容放在协调器布局中!为什么android:layout|u gravity=“bottom | end”不起作用?FAB位于左侧,顶部添加
android:fitSystemWindow=“true”
到协调器布局中
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"