2016-03-06 125 views
1

我GOOGLE了我的問題,並閱讀了類似的問題在stackoverflow但我沒有解決任何方式。ScrollView不滾動片段

我有coordinatorLayout(main.xml中)並用的RelativeLayout片段(fragment.xml之)

main.xml中的佈局

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    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:paddingRight="16dp" 
     app:layout_scrollFlags="scroll|enterAlways" 
     app:popupTheme="@style/AppTheme.PopupOverlay"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:layout_weight="1"> 
       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="40dp" 
        android:text="FRAGMENT TITLE" 
        android:textSize="20sp" 
        android:textColor="@color/colorWhite" 
        android:id="@+id/main_toolbar_title" 
        android:gravity="center_vertical" /> 
      </LinearLayout> 
     </LinearLayout> 
    </android.support.v7.widget.Toolbar> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:background="@color/colorWhite" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" /> 
</android.support.design.widget.AppBarLayout> 

<android.support.v4.view.ViewPager 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

個fragment.xml之

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="10dp" 
android:background="#f3f3f3"> 

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

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

     <android.support.v7.widget.CardView 
      android:id="@+id/card_view" 
      android:layout_gravity="center" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      card_view:contentPadding="1dp" 
      card_view:cardCornerRadius="2dp"> 

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

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="66dp" 
        android:textAllCaps="false" 
        android:text="Button Title" 
        android:textSize="18sp" 
        android:textColor="#404040"/> 
       <Button 
        android:layout_width="match_parent" 
        android:layout_height="66dp" 
        android:textAllCaps="false" 
        android:text="Button Title" 
        android:textSize="18sp" 
        android:textColor="#404040"/> 
       <Button 
        android:layout_width="match_parent" 
        android:layout_height="66dp" 
        android:textAllCaps="false" 
        android:text="Button Title" 
        android:textSize="18sp" 
        android:textColor="#404040"/> 
       <Button 
        android:layout_width="match_parent" 
        android:layout_height="66dp" 
        android:textAllCaps="false" 
        android:text="Button Title" 
        android:textSize="18sp" 
        android:textColor="#404040"/> 
       <Button 
        android:layout_width="match_parent" 
        android:layout_height="66dp" 
        android:textAllCaps="false" 
        android:text="Button Title" 
        android:textSize="18sp" 
        android:textColor="#404040"/> 
       <Button 
        android:layout_width="match_parent" 
        android:layout_height="66dp" 
        android:textAllCaps="false" 
        android:text="Button Title" 
        android:textSize="18sp" 
        android:textColor="#404040"/> 
       <Button 
        android:layout_width="match_parent" 
        android:layout_height="66dp" 
        android:textAllCaps="false" 
        android:text="Button Title" 
        android:textSize="18sp" 
        android:textColor="#404040"/> 
       <Button 
        android:layout_width="match_parent" 
        android:layout_height="66dp" 
        android:textAllCaps="false" 
        android:text="Button Title" 
        android:textSize="18sp" 
        android:textColor="#404040"/> 

      </LinearLayout> 
     </android.support.v7.widget.CardView> 
    </LinearLayout> 
</ScrollView> 
</RelativeLayout> 

正如你所看到的,我已經在滾動視圖而不是滾動更多的按鈕。查看尋呼機中的ui元素,我首先認爲這是因爲查看尋呼機,但我測試它test_fragment.xml,它完美的作品。

滾動視圖滾動時,我按住了看法尋呼機(例如:我的第一個標籤) 和移動手指向上/向下

test_fragment.xml

<android.support.design.widget.CoordinatorLayout 
android:id="@+id/quickreturn_coordinator" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

問題是什麼?

在此先感謝。

回答

5

由於您正在使用AppBarLayout,因此無法使用簡單的ScrollView。您應該使用NestedScrollview。並且您已將ScrollView放入RelativeLayout內部,這不是必需的。請嘗試使用NestedScrollView刪除RelativeLayout

我想這會有所幫助。

+0

謝謝,它的工作。我接受你的回答,再次感謝! –

+0

很高興聽到.. :) –

+1

幫助我解決了這個問題,很難找到問題(AppBarLayout與滾動視圖),你是如何識別這個問題:)? – Amritesh