2016-05-20 8 views
8

リニアレイアウト内のコンテンツを含むネストされたScrollViewがあります。AndroidネストされたScrollviewがスクロールしない

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:CoverFlowPager="http://schemas.android.com/apk/res-auto" 
    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"> 

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/scroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="10dp" 
     android:clipToPadding="false" 
     android:fillViewport="true" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

    </android.support.v4.widget.NestedScrollView> 

</FrameLayout> 

私はViewPagerとViewPagerの内側にこのレイアウトを持っているがCordinatorLayoutの内側にあります。

<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:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

私がビューをスクロールすると、ビューはスクロールしていません。しかし、レイアウトはコーディネーターのレイアウト内に配置されているので、ToolBarが隠されるまで上に移動します。しかし、それはスクロールアップしていません。

ここは私の主な活動のXMLです。ビューページャはタブ付きレイアウトの中にあります。ビューがスクロールアップされるとここで

<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:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <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 xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       xmlns:attrs="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="?attr/colorPrimary" 
       app:layout_scrollFlags="scroll|enterAlways" 
       app:popupTheme="@style/AppTheme.PopupOverlay"> 

      <FrameLayout 
       android:id="@+id/titleContainer" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center"  
       android:gravity="center"> 

       <com.CustomFontTextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:text="Toolbar Title" 
        android:textColor="#ffffff" 
        attrs:customFont="handyman_bold" 
        android:textSize="8pt" 
        android:layout_marginLeft="-20dp" 
        android:id="@+id/toolbar_title"/> 
      </FrameLayout> 

      <ImageButton 
       android:id="@+id/btn_ToolBarRightBtn" 
       android:layout_width="32dp" 
       android:layout_height="28dp" 
       android:tag="0" 
       android:background="@null" 
       android:scaleType="fitXY" 
       android:src="@drawable/icon_shopping" 
       android:layout_alignParentRight="true" 
       android:layout_gravity="right" 
       android:layout_marginRight="10dp" 
       /> 

     </android.support.v7.widget.Toolbar> 

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

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_gravity="bottom" 
     android:background="@color/offwhite" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

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

初期ビュー enter image description here

、私のスクリーンショットで、それだけで上部のナビゲーションバーを非表示にスクロールします。そのタブバー以下の項目を表示するにはスクロールしない、

enter image description here

+0

は 'アンドロイドべきではない:NestedScroolビューでlayout_height = "match_parentは"' 'アンドロイドこと:layout_height = "wrap_content"' ...ネストされた線形レイアウトでも同様です。 – longilong

+0

達成しようとしているものを視覚的に追加できますか? – jobbert

+0

スクリーンショットをご覧ください – Zach

答えて

1

app:layout_behavior="..."はCoordinatorLayoutの直接の子に設定する必要があります。 ViewPagerがCoordinatorLayoutの直属の子である場合は、ViewPager宣言に配置してください。ここから

0

引用:layout_behaviorプロパティをViewPagerにoutlined hereように:Troubleshooting Coordinator Layouts

ViewPagerと親アクティビティ内のアイテムのリストをフラグメント間の連携、アプリを入れたいですポケベル内のスクロールが泡立ち、CoordinatorLayoutによって管理されます。 layout_behaviorプロパティは、そのアプリケーションの中のどこにでも置くことはできません。

0

これを試すことができます。私は私のアプリで同じ問題を抱えていた。これは私のために働いた。

<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 xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:attrs="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways" 
     app:popupTheme="@style/AppTheme.PopupOverlay"> 

     <FrameLayout 
      android:id="@+id/titleContainer" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 

      android:gravity="center"> 

      <com.CustomFontTextView 
       android:id="@+id/toolbar_title" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="-20dp" 
       android:gravity="center" 
       android:text="Toolbar Title" 
       android:textColor="#ffffff" 
       android:textSize="8pt" 
       attrs:customFont="handyman_bold" /> 
     </FrameLayout> 

     <ImageButton 
      android:id="@+id/btn_ToolBarRightBtn" 
      android:layout_width="32dp" 
      android:layout_height="28dp" 
      android:layout_alignParentRight="true" 
      android:layout_gravity="right" 
      android:layout_marginRight="10dp" 
      android:background="@null" 
      android:scaleType="fitXY" 
      android:src="@drawable/icon_shopping" 
      android:tag="0" /> 


    </android.support.v7.widget.Toolbar> 

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:background="@color/offwhite" /> 


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


</LinearLayout> 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/scroll" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="10dp" 
    android:clipToPadding="false" 
    android:fillViewport="true"> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"></LinearLayout> 
</android.support.v4.widget.NestedScrollView> 

0

だからここにあなたがでframeLayout内NestedScrollViewを持つことができない問題です。

また、xmlに必要な小さな変更が必要です。 TabLayoutがAppBarレイアウト内にあり、固定されている必要があります。

ここにあなたのコードだ - >

</android.support.v7.widget.Toolbar> 

<android.support.design.widget.TabLayout 
android:id="@+id/tabs" 
android:layout_gravity="bottom" 
android:background="@color/offwhite" 
android:layout_width="match_parent" 
app:layout_collapseMode="pin" 
app:layout_anchor="@+id/appbar" 
app:layout_anchorGravity="bottom" 
android:layout_height="wrap_content"/> 

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

と - >フレームレイアウトを削除するには、あなたのフラグメントのコードを変更します!

<android.support.v4.widget.NestedScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:CoverFlowPager="http://schemas.android.com/apk/res-auto" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/scroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="10dp" 
     android:clipToPadding="false" 
     android:fillViewport="true"> 

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

    </android.support.v4.widget.NestedScrollView> 

希望します。

+0

@Zach私は答えを更新してください。 –

0

scroll.setOnTouchListener(new View.OnTouchListener() { 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     v.getParent().requestDisallowInterceptTouchEvent(true); 
     return false; 
    } 
}); 
0

ScrollingViewBehaviorこれを試すにはちょうどあなたのViewPagerにオフセット上下を追加しています。一般に、オフセットはAppBarLayoutの高さに依存し、AppBarLayoutにはないので、TabLayoutの高さに依存しません。そのため、迅速な対応策については、あなただけのこのようなあなたのViewPagerにpaddingBottomのを追加することができます。

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

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_gravity="bottom" 
     android:background="@android:color/black" 
     android:layout_width="match_parent" 
     android:layout_height="50dp"/> 
関連する問題