2

I CoordinatorLayout und NestedScrollView verwende sieht wie folgt aus einer Aktivität für die Erstellung von: enter image description hereCoordinatorLayout und RecyclerView Ausgabe

Meine Layout-Struktur ist wie folgt:

<android.support.design.widget.CoordinatorLayout   
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:custom="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".activity.MovieDetailActivity"> 

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

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsingToolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleMarginStart="48dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <ImageView 
       android:id="@+id/imgToolbarImage" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true" 
       android:scaleType="centerCrop" 
       android:src="@drawable/backdrop" 
       app:layout_collapseMode="parallax" /> 

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

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

     <android.support.v4.widget.NestedScrollView 
      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"> 

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

       <android.support.v7.widget.CardView 
        ... > 
        <ImageView 
         ... /> 
       </android.support.v7.widget.CardView> 

       <TextView 
         ... /> 

       <TextView 
         ... /> 

       <ImageView 
         ... /> 

       <TextView 
        ... /> 

       <com.aminiam.moviekade.custom_view.ExpandableTextView 
        ... /> 

       <android.support.v4.view.ViewPager 
        ... /> 

       <com.aminiam.moviekade.custom_view.DotIndicator 
        ... /> 

       <View 
        ... /> 

       <LinearLayout 
        ... > 

        <TextView 
         ... /> 

        <android.support.v7.widget.RecyclerView 
         ... /> 
       </LinearLayout> 

       <android.support.v4.view.ViewPager 
        ... /> 

       <TextView 
        ... /> 
      </RelativeLayout> 

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

    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/activity_horizontal_margin" 
     app:layout_anchor="@id/appBar" 
     app:layout_anchorGravity="bottom|end" 
     app:srcCompat="@drawable/ic_favorite_off" /> 
</android.support.design.widget.CoordinatorLayout> 

Wenn ich RecyclerView das Layout, NestedScrollView hinzufügen Wille geht unter dem AppBarLayout, wie Bild unten:

enter image description here

Ich habe einige Möglichkeiten getestet, um dieses Problem zu beheben, wie NestedScrollView in ein FrameLayout einfügen oder android:layout_gravity="fill_vertical" und android:fillViewport="true" Attribute zu NestedScrollView hinzufügen, aber das konnte das Problem nicht beheben.

+0

Wie hoch ist 'recyclerview'? 'wrap_content'? – Wizard

+0

Nein, ich habe eine feste Höhe dafür hinzugefügt. android: layout_height = "150dp" – hosseinAmini

Antwort

4

Try android:descendantFocusability="blocksDescendants" in Ihre RelativeLayout

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

</RelativeLayout> 

Hinweis hinzufügen:descendantFocusability Definiert die Beziehung zwischen dem Viewgroup und seine Nachkommen, wenn eine Ansicht, die Fokus zu nehmen. Hier blockieren wir das.

+0

Das ist genau die richtige Antwort. Ich danke dir sehr – hosseinAmini

Verwandte Themen