简体   繁体   English

浮动动作按钮显示在右上角,而不是右下角的android

[英]Floating action button displaying on top right instead of bottom right android

This is my parent layout where i am including FAB. 这是我包括FAB的父母的布局。

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

<android.support.v4.widget.DrawerLayout
    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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:id="@+id/coordinatorLayout"
        android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <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"
            app:tabIndicatorColor="@android:color/white"
            app:tabIndicatorHeight="4dp"
            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>


    </RelativeLayout>


    <include layout="@layout/floating_button"/>

    </android.support.design.widget.CoordinatorLayout>

    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="com.wokoshop.sony.app.FragmentDrawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer" />


</android.support.v4.widget.DrawerLayout>

This is actual FAB layout. 这是实际的FAB布局。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

<android.support.design.widget.FloatingActionButton
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
    android:clickable="true"
    android:src="@drawable/cart"
    android:layout_margin="20dp"
    app:elevation="6dp" />

</FrameLayout>

This FAB is displaying in top right in layout. 该FAB显示在布局的右上方。 I want to display it on bottom right. 我想在右下角显示它。

Can anyone help me on this? 谁可以帮我这个事?

Include your FAB layout in your parent layout giving layout_alignParentBottom property true: 将FAB布局包括在父布局中,使layout_alignParentBottom属性为true:

    <include layout="@layout/activity_dialog"
     android:layout_alignParentBottom="true"
     android:layout_alignParentRight="true"
     android:layout_height="wrap_content"
     android:layout_width="wrap_content"/>  

Also try to change CoordinatorLayout android:layout_height="fill_parent" : 也尝试更改CoordinatorLayout android:layout_height =“ fill_parent”:

    <android.support.design.widget.CoordinatorLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:id="@+id/coordinatorLayout"
    android:orientation="vertical">

Remove the <include> tag. 删除<include>标签。

Place your FAB in its place with the <anchor> tag: 使用<anchor>标签将FAB放在其位置:

app:layout_anchorGravity="bottom|right|end" 应用:layout_anchorGravity = “底部|右|结束”

<android.support.design.widget.FloatingActionButton
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_anchorGravity="bottom|right|end"
    android:clickable="true"
    android:src="@drawable/cart"
    android:layout_margin="20dp"
    app:elevation="6dp" />

If you still aren't winning, revise your layout by referring to this: FAB in the corner. 如果您仍然没有赢,请参考以下说明修改布局: FAB在角落。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM