Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android xml片段中ListView上方的浮动操作按钮(FAB)?_Android_Xml_Listview_Android Fragments_Floating Action Button - Fatal编程技术网

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"