2016-03-06 72 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