2016-06-30 69 views
-1

enter image description here浮動操作按鈕上方滾動視圖

我怎麼能位置上方滾動型佈局浮動按鈕...我試圖滾動型定位和相對佈局內的按鈕(的FrameLayout)的容器,但這種方式也不能正常工作... xml文件:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:weightSum="100"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/no_size" 
    android:layout_weight="92"> 

    <LinearLayout 
     android:id="@+id/questionContainer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <com.rey.material.widget.TextView 
      android:id="@+id/surveyTitleTtv" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="12dp" 
      android:textSize="20sp" 
      android:textStyle="bold" 
      android:textColor="@android:color/black" /> 

     <com.rey.material.widget.TextView 
      android:id="@+id/test" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="12dp" 
      android:layout_marginLeft="12dp" 
      android:layout_marginBottom="12dp" 
      android:textColor="@color/accentColor" 
      android:textSize="17dp" 
      android:textStyle="bold" /> 

    </LinearLayout> 

</ScrollView> 

<FrameLayout 
    android:id="@+id/bottomSheetLlt" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_weight="8" 
    android:background="@android:color/white"> 

    <com.rey.material.widget.FloatingActionButton 
     android:id="@+id/saveQuestionBtn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:layout_marginTop="-20dp" 
     android:text="ADD" 
     app:elevation="2dp" /> 

</FrameLayout> 

請誰能告訴我是怎麼回事?

回答

1

最後,我設法解決了這個問題..問題是我試圖將FAB放在片段佈局中,這顯然是不可行的。我將其作爲CoordinatorLayout的子項移動到我的活動xml佈局中,現在實際上是一個「浮動」操作按鈕...

0

只動FloatingButton上面滾動視圖中的XML佈局

0

你需要來定位CoordinatorLayoutFloatingActionButton並使用CoordinatorLayout作爲活動的根源。 (FloatingActionButton依賴於CoordinatorLayout啓用的功能)如果您的scrollview是一個片段內部,這仍然可以 - 只要您將一個ID分配給FloatingActionButton,您就可以從片段中引用它。

+0

我剛纔想it..but它仍然躲在下面bottomSheetLlt的FrameLayout – tsiro

+0

請張貼這是有關什麼用戶看到的是看到所有的佈局文件。我們可以修改。 – apelsoczi

+0

這是我在上面發佈的代碼的一個佈局文件... – tsiro

0

用下面的代碼替換您的xml代碼。您需要使用相對佈局或協調員佈局作爲根佈局。只需在framelayout之外放置floatig動作按鈕即可。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

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

    <LinearLayout 
     android:id="@+id/questionContainer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <com.rey.material.widget.TextView 
      android:id="@+id/surveyTitleTtv" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="12dp" 
      android:textColor="@android:color/black" 
      android:textSize="20sp" 
      android:textStyle="bold" /> 

     <com.rey.material.widget.TextView 
      android:id="@+id/test" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="12dp" 
      android:layout_marginLeft="12dp" 
      android:layout_marginRight="12dp" 
      android:textColor="@color/accentColor" 
      android:textSize="17dp" 
      android:textStyle="bold" /> 

    </LinearLayout> 

</ScrollView> 

<com.rey.material.widget.FloatingActionButton 
    android:id="@+id/saveQuestionBtn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentRight="true" 
    android:layout_gravity="bottom|right|end" 
    android:layout_marginBottom="16dp" 
    android:layout_marginEnd="16dp" 
    android:layout_marginRight="16dp" 
    android:text="ADD" 
    app:elevation="2dp" />