2016-10-13 7 views
1

In meiner App habe ich ein Fragment mit horizontalem ViewPager und horizontalen RecycleViews, das sich unter vertikalem ScrollView befindet. Mein Problem ist, dass der ViewPager den übergeordneten vertikalen Bildlauf blockiert. Ich habe versucht, das vertikale TouchPar-Ereignis von ViewPager zu deaktivieren, aber es hat nicht geholfen. Hier ist ein Video, das das Problem zeigt:Horizontaler ViewPager in vertikaler ScrollView

https://drive.google.com/file/d/0B9XMTJsXn0ofQnpOcWo5TW9GLWs/view?usp=sharing

Und hier ist mein Layout xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/scrollView" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:scrollbars="none"> 

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

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

     <ViewPager 
      android:id="@+id/viewPager" 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:layout_gravity="top" 
      android:visibility="gone" /> 

     <InkPageIndicator 
      android:id="@+id/page_indicator" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_marginEnd="@dimen/activity_horizontal_margin" 
      android:layout_marginStart="@dimen/activity_horizontal_margin" 
      android:paddingBottom="8dp" 
      android:visibility="gone" /> 
    </RelativeLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/selectableItemBackground" 
     android:clickable="true" 
     android:minHeight="48dp" 
     android:visibility="gone"> 

     <FrameLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_weight="1.0" 
      android:orientation="horizontal"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginStart="16dp" 
       android:text="@string/software" 
       android:textColor="?android:textColorPrimary" 
       android:textSize="20sp" /> 
     </FrameLayout> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_marginEnd="@dimen/activity_horizontal_margin" 
      android:layout_marginStart="@dimen/activity_horizontal_margin" 
      android:text="@string/see_all" 
      android:textAppearance="@style/TextAppearance.Button" 
      android:textColor="?colorAccent" /> 
    </LinearLayout> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/software_recyclerView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="4dp" 
     android:visibility="gone" /> 
</LinearLayout> 

+0

es nicht sehr empfehlenswert Scroll innerhalb Scroll in Android zu verwenden. –

+0

Ja, ich weiß, aber immer noch, es muss eine richtige Art und Weise zu tun, dass so viele beliebte Apps gleiche Funktion (Google Play Store zum Beispiel) hat. – shnizlon

Antwort

0

Sie verwenden Linearlayout dann können Sie einstellen,

Android: GewichtSumme

Eigenschaft zur Behebung dieses Problems.

+0

Vielen Dank für Ihren Kommentar, ich habe gerade versucht, dass und leider hat es nicht um das Problem zu lösen .. – shnizlon

0

Verwenden Sie ein CoordinatorLayout anstelle von Scrollview, legen Sie den View-Pager in das CollapsingToolbarLayout und den Rest der Layouts in der NestedScrollView.

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/background_light" 
android:fitsSystemWindows="true"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/main.toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/main.appbar" 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/main.collapsing" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary"> 

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

      <ViewPager 
       android:id="@+id/viewPager" 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:layout_gravity="top" 
       android:visibility="gone" /> 

      <InkPageIndicator 
       android:id="@+id/page_indicator" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_marginEnd="@dimen/activity_horizontal_margin" 
       android:layout_marginStart="@dimen/activity_horizontal_margin" 
       android:visibility="gone" /> 
     </RelativeLayout> 
    </android.support.design.widget.CollapsingToolbarLayout> 
</android.support.design.widget.AppBarLayout> 

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

    // Put the layouts and views here, those you want to show below the view pager. 
</android.support.v4.widget.NestedScrollView> 

Verwandte Themen