Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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_Android - Fatal编程技术网

如何在右下角显示浮动操作按钮-android

如何在右下角显示浮动操作按钮-android,android,Android,我正在使用这个布局文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/main_layout" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="htt

我正在使用这个布局文件

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    android:id="@+id/main_layout"
    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=".ActivityStartShopping">


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="@color/primary"
        android:elevation="6dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        android:background="@color/primary"
        android:elevation="6dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tab_layout"
        android:paddingTop="20dp"
        android:background="@color/windowBackground"
        android:layout_above="@id/bottomButtons"
        >
    </android.support.v4.view.ViewPager>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@drawable/cart"
        android:layout_gravity="bottom|end"
        />

</RelativeLayout>

对于我来说,浮动操作按钮显示在左上角

如何在右下角显示它。

将您的根相对定位更改为android.support.design.widget.CoordinatorLayout

将您的根相对定位更改为android.support.design.widget.CoordinatorLayout尝试以下代码:

<android.support.design.widget.FloatingActionButton
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    app:pressedTranslationZ="12dp"
    app:elevation="6dp" />

最好使用CoordinatorLayout

尝试以下代码:

<android.support.design.widget.FloatingActionButton
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    app:pressedTranslationZ="12dp"
    app:elevation="6dp" />


最好使用CoordinatorLayout

对于这样的设计,您必须包括
依赖项
,这将添加到
build.gradle的
应用程序
模块的
依赖项
块下

compile 'com.android.support:design:23.1.1'

如果没有此选项,您将无法使用
CoordinatorLayout
FloatingActionButton

我几乎没有改变资源,因为我没有你在问题中展示的资源

布局



对于这样的设计,您必须包括
依赖项
,这将添加到
build.gradle的
应用程序
模块的
依赖项
块下

compile 'com.android.support:design:23.1.1'

如果没有此选项,您将无法使用
CoordinatorLayout
FloatingActionButton

我几乎没有改变资源,因为我没有你在问题中展示的资源

布局



尝试在
fab
中添加
android:layout\u alignParentBottom=“true”
android:gravity=“bottom | end”
?感谢您的回复。我根据你的建议做了改变。现在它显示在左下角。如何在右下角显示。在
fab
中添加
bottom | right
而不是
end
。尝试添加
android:layout\u alignParentBottom=“true”
android:gravity=“bottom | end”
,谢谢回复。我根据你的建议做了改变。现在它显示在左下角。如何在右下角显示。添加
bottom | right
而不是
end