2017-10-10 119 views
0

我有一個滾動視圖與片段容器內的三個視圖尋呼機。我想要放置一個固定的浮動操作按鈕,如Gmail的收件箱在頁面的右下方,而不是在右下方的scrollview.It應該是固定的我是否滾動或not.I我張貼我的抽屜佈局XML file.please幫我固定位置浮動操作按鈕像gmail android

<?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"/> 

回答

6

您需要使用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文件中的所有其他組件