2016-03-18 19 views
2

ViewPagerでCoordinatorLayoutで構成されたビューを実装しようとしています.NestedScroolViewは各ViewPagerの内部にあります。水平スクロールを処理するためにViewPager内のNestedScrollViewを停止します

ビューページャのコンテンツを変更するために左右にスワイプすると、ジェスチャがNestedScrollViewに転送されて、時々、次のような問題が発生することがありました。非常に小さい垂直スクロール。それは小さいですが、迷惑になるほどで​​す。

これは、より良い問題を説明する必要があります

Example of behavior

ビデオ:https://youtu.be/BGqynDDL68I

私はスクロール/情事の方法をブロックするようにNestedScrollViewを拡張しようとしたんが、何も成功しました。

誰もが同じ問題を抱えていますか?

EDIT 1:コード

活動:

<?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" 
    tools:context="main.MainActivity" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!--<include layout="@layout/main__activitycontent"/>--> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/id_appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/main__toolbar" 
      android:fitsSystemWindows="true" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/AppTheme.PopupOverlay"/> 

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


    <FrameLayout 
     android:id="@+id/main__fragment_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/main__navigations_tablayout" 
     android:layout_width="match_parent" 
     android:layout_height="56dp" 
     android:layout_gravity="bottom" 
     android:background="@color/main__tabbar_button_color" 
     app:layout_behavior="utils.views.TabLayoutBehaviour" 
     app:tabIndicatorColor="@android:color/white" 
     app:tabSelectedTextColor="@color/main__tabbar_selected_color" 
     app:tabTextColor="@color/main__tabbar_normal_color" 
     > 


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

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

断片とViewPager

<android.support.v4.view.ViewPager 
    android:id="@+id/meditationpager__pager" 

    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" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    /> 

インナーフラグメント:

<android.support.v4.widget.NestedScrollView 
    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" 
    android:background="@android:color/white" 
    android:fillViewport="true" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="main.MainActivity" 
    tools:showIn="@layout/main__activity"> 

    <LinearLayout 
     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="wrap_content" 
     android:orientation="vertical" 
     tools:context="domain.screens.readmeditation.MeditationFragment"> 


     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="@string/large_text"/> 

    </LinearLayout> 
</android.support.v4.widget.NestedScrollView> 
+0

ちょうどメモ:下部のバーは、ViewPagerにリルートされていない、ナビゲーションバーです。 –

+0

私が見ることができるもののために、下のバーには "下に目を向ける"があります。私は正しい? – royB

+0

ええと、ツールバーも少し上に行く(下のバーの動作はツールバーに依存しないので、ツールバーが動いたときに下のバーが反対方向に動く) –

答えて

0

きれいな溶液がNestedScrollViewを拡張して、このようonTouchイベントを上書きしました:yVectorがxVectorよりも大きい場合は、この方法を

public class VerticalOnlyNestedScrollView extends NestedScrollView { 
    private static final String TAG = "VOnlyNestedScrollView"; 
    public VerticalOnlyNestedScrollView(Context context) { 
     super(context); 
    } 

    private float startX, startY; 

    public VerticalOnlyNestedScrollView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public VerticalOnlyNestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 


    @Override 
    public boolean onTouchEvent(MotionEvent ev) { 

     if (!(ev.getAction()== MotionEvent.ACTION_DOWN)&& ev.getHistorySize() > 0) { 


      float yVector = ev.getY() - ev.getHistoricalY(0); 
      float xVector = ev.getX() - ev.getHistoricalX(0); 
      Log.d(TAG, "onInterceptTouchEvent: " + xVector + "--" + yVector); 

      return Math.abs(yVector) <= Math.abs(xVector) || super.onTouchEvent(ev); 
     } 

     return super.onTouchEvent(ev); 
    } 
} 

、親onTouchのみが処理されます。

+0

残念なことに:( – dgngulcan

+0

完全に同じコードを使って完全に動作しています。より多くのコンテキストを提供できますか? –

1

がこのようなあなたの活動の構造を変更してみてください:

<?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" 
     tools:context="main.MainActivity" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    <!--<include layout="@layout/main__activitycontent"/>--> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/id_appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/main__toolbar" 
      android:fitsSystemWindows="true" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/AppTheme.PopupOverlay"/> 

    </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.v4.view.ViewPager 
      android:id="@+id/meditationpager__pager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/main__navigations_tablayout" 
      android:layout_width="match_parent" 
      android:layout_height="56dp" 
      android:layout_gravity="bottom" 
      android:background="@color/main__tabbar_button_color" 
      app:tabTextColor="@color/main__tabbar_normal_color" 
      app:tabSelectedTextColor="@color/main__tabbar_selected_color" 
      app:tabIndicatorColor="@color/white"/> 

    </LinearLayout> 

ビューポケットベルを使用してフラグメントは、もはや必要ではないだろうとセットアップ使用して見ることができるこの方法:私は信じて

private void setupViewPager() { 
    MyAdapter adapter = new MyAdapter(getSupportFragmentManager()); 

    InnerFragment fragment = new InnerFragment(); 
    adapter.addFragment(fragment); 

    mViewPager.setAdapter(adapter); 
} 

をこの方法では、NestedScrollViewのlayout_behaviorを設定する必要はありません。私が見つけた

関連する問題