0

は私のレイアウトは非常にシンプルであるAPI 21 に追加された機能:ネストされたスクロール(Horizo​​ntalScrollView内部Horizo​​ntalScrollView)

Horizo​​ntalScrollView のLinearLayout(水平明らかに) 正規ビュー Horizo​​ntalScrollView TextView

デフォルトでは、nestedScrollEnabledはfalseです。だから、私は子供のためにXMLでそれを有効にしました(例えばHorizo​​ntalScrollViewの内側)私はルートHorizo​​ntalScrollViewの優先順位でスクロールしたいです。 したがって、何もしません。一番上のスクロールビューのみスクロールすることができ、内のスクロールビューはスクロールすることはできません。

<?xml version="1.0" encoding="utf-8"?> 
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/scrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.majeur.test.MainActivity"> 

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

     <HorizontalScrollView 
      android:id="@+id/scrollView2" 
      android:layout_width="200dp" 
      android:layout_height="match_parent" 
      android:nestedScrollingEnabled="true"> 

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

     </HorizontalScrollView> 

     <View 
      android:layout_width="200dp" 
      android:layout_height="match_parent" 
      android:background="@color/colorAccent"/> 


    </LinearLayout> 
</HorizontalScrollView> 

それは

答えて

-1

が向き、水平に子供のLinearLayoutでNestedScrollViewを使用してみてください、それは作品が、私は理解していないはずですWAU ... おかげです。

NestedScrollViewはちょうどScrollViewのようですが、それは両方の新旧バージョンのAndroidの に ネストされたスクロール親と子の両方として機能をサポートしています。ネストされたスクロールはデフォルトで有効になっています。

https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html

+0

....

// Intercept touch scroll by transparentImageView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: // Disallow ScrollView to intercept touch events. scrollView.requestDisallowInterceptTouchEvent(true); // Disable touch on transparent view return false; case MotionEvent.ACTION_UP: // Allow ScrollView to intercept touch events. scrollView.requestDisallowInterceptTouchEvent(false); return true; case MotionEvent.ACTION_MOVE: scrollView.requestDisallowInterceptTouchEvent(true); return false; default: return true; } } }); 

そして、あなたのXMLを.v4.widget.NestedScrollViewはexaでなければなりませんctlyはフレームワークのScrollViewと同じです。とにかく私はサポートライブラリで試してみます。入れ子にされたスクロールは非常にひどく文書化されていますが、NestedScrollViewのサポートが垂直なScrollViewであるかどうか、またはどの軸でそれがスクロール可能であるかを判断することはできません。 – Pdroid

0

あなたはonTouchListener使用してタッチをインターセプトする必要があります:API 21+サポートで

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/scrollView1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.majeur.test.MainActivity"> 

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


    <RelativeLayout 
      android:id="@+id/mapLayout" 
      android:layout_width="match_parent" 
      android:layout_height="300dp" 
    <HorizontalScrollView 
     android:id="@+id/scrollView2" 
     android:layout_width="200dp" 
     android:layout_height="match_parent" 
     android:nestedScrollingEnabled="true"> 

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

    </HorizontalScrollView> 
       <ImageView 
       android:id="@+id/transparent_image" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       /> 
    </RelativeLayout> 

    <View 
     android:layout_width="200dp" 
     android:layout_height="match_parent" 
     android:background="@color/colorAccent"/> 


</LinearLayout> 

+0

あなたの助けてくれてありがとうが、私が欲しいものではありません!その解決策の問題は、子がもうスクロールできなくなったときに親にスクロールスクロールしないことです。これは、ネストされたスクロール "フレームワーク"のすべての目的であり、階層内のさまざまなビュー間でスクロールを同期させることができます。 – Pdroid

+0

私たちがここでやろうとしていることは、親スクロールをブロックしてロックダウンしていないということです。これをインターセプトしています...つまり、ユーザーが内側スクロールをスクロールするときに内側スクロールを有効にするために、いずれかの方法で親スクロールには影響しません。少なくとも私の場合はそうではありません! – MezzyDroid

関連する問題