固定位置浮动动作按钮就像gmail android

时间:2017-10-10 12:20:11

标签: android floating-action-button

我在一个片段容器中有一个带有三个视图寻呼机的滚动视图。我想在页面右下方放置一个固定的浮动动作按钮,如gmail收件箱,而不是在滚动视图的右下角。我应该修复是否我滚动或不滚动。我发布了我的抽屉布局xml文件。请帮助我

<?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"
android:id="@+id/drawer_layout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.efflorescence.settingneeds.HomeActivity">

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="1sp"
        android:background="@android:color/white"/>
    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar"/>

    <!--fragment container-->
    <FrameLayout
        android:id="@+id/container"
        android:visibility="gone"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        </FrameLayout>
    <!--Home Page Content put here-->

    <ScrollView
        android:id="@+id/svcontent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none"
        android:background="@android:color/white"
        android:layout_marginTop="0dp">

        <RelativeLayout
            android:id="@+id/home_main_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <TextView
                android:id="@+id/pro_req_heading"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="#2094c5"
                android:textColor="@android:color/white"
                android:gravity="center"
                android:text="[ IMMEDIATE REQUIREMENT ]"/>

                <RelativeLayout
                    android:id="@+id/product_req_container"
                    android:layout_width="match_parent"
                    android:layout_height="300dp"
                    android:layout_below="@+id/pro_req_heading"
                    android:layout_marginBottom="1dp">

                  <android.support.v4.view.ViewPager
                          android:id="@+id/pager1"
                          android:layout_width="fill_parent"
                          android:layout_height="fill_parent"
                          android:layout_alignParentTop="true"/>
                 </RelativeLayout>

            <TextView
                android:id="@+id/pro_review_heading"
                android:layout_marginTop="0dp"
                android:layout_width="match_parent"
                android:layout_below="@+id/product_req_container"
                android:layout_height="50dp"
                android:background="#2094c5"
                android:textColor="@android:color/white"
                android:gravity="center"
                android:text="[ MOST REVIEW PRODUCTS ]"/>

            <RelativeLayout
                android:id="@+id/product_review_container"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:layout_below="@+id/pro_review_heading">

                <android.support.v4.view.ViewPager
                    android:id="@+id/pager2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"/>
            </RelativeLayout>

            <TextView
                android:id="@+id/pro_sale_heading"
                android:layout_marginTop="0dp"
                android:layout_width="match_parent"
                android:layout_below="@+id/product_review_container"
                android:layout_height="50dp"
                android:background="#2094c5"
                android:textColor="@android:color/white"
                android:gravity="center"
                android:text="[ MOST SALE PRODUCTS ]"/>

            <RelativeLayout
                android:id="@+id/product_sale_container"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:layout_alignParentBottom="true"
                android:layout_below="@+id/pro_sale_heading">

                <android.support.v4.view.ViewPager
                    android:id="@+id/pager3"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_alignParentBottom="true"/>

            </RelativeLayout>


         </RelativeLayout>
    </ScrollView>

</LinearLayout>

<fragment
    android:id="@+id/nav_drwr_fragment"
    android:layout_width="@dimen/nav_drawer_width"
    android:layout_height="match_parent"
    android:name="com.example.efflorescence.settingneeds.navigation.NavigationFragment"
    android:layout_gravity="start"
    tools:layout="@layout/fragment_navigation"/>

1 个答案:

答案 0 :(得分:4)

您需要使用CoordinatorLayout

<强> main.xml中

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
    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="com.example.c217.reddyteacherapp.baseActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />

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

并将所有其他组件放在content_base xml文件中

相关问题