0

Ich habe eine scrollende AppBarLayout innerhalb der CoordinatorLayout, und ich schließe ein anderes Layout innerhalb der ersten, die eine NestedScrollView, RecyclerView und einige andere Ansichten hat.Letzter Artikel in Recyclerview (in einem NestedScrollview) ist geschnitten, Querformat schneidet den Viewpager

Ich habe ein paar Probleme, denen ich in diesem Layout gegenüberstehe.

  1. keine glatten Scrollen in der Aktivität, im Innern der RecyclerView scrollt es reibungslos.

  2. Der letzte Artikel im RecyclerView wird von unten abgeschnitten.

  3. Wenn ich die Ausrichtung ändere schneidet es den ViewPager ganz unten ab. Da ich nicht mehr blättern kann.

Item in the RecyclerView is cut

Orientation cuts the ViewPager

ich auch das Haupt-Layout und die untergeordneten Layouts unten bin Befestigung.

activity_detail.xml

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".DetailActivity"> 

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

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

      <ImageView 
       android:id="@+id/iv_movie_backdrop" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/str_movie_backdrop_image" 
       android:scaleType="fitXY" /> 

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

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

    <include layout="@layout/movie_details" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/fab_margin" 
     app:layout_anchor="@id/app_bar" 
     app:layout_anchorGravity="bottom|end" 
     app:srcCompat="@drawable/ic_favorite_black_24dp" /> 

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

movie_details.xml

<?xml version="1.0" encoding="utf-8"?> 
<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:fillViewport="true" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.CardView 
      android:id="@+id/cv_poster_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginStart="10dp" 
      android:layout_marginTop="10dp" 
      android:elevation="@dimen/card_elevation" 
      app:cardCornerRadius="8dp" 
      app:cardUseCompatPadding="true" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toTopOf="parent"> 

      <ImageView 
       android:id="@+id/iv_movie_poster" 
       android:layout_width="150dp" 
       android:layout_height="200dp" 
       android:contentDescription="@string/str_movie_poster" 
       android:padding="@dimen/poster_padding" 
       android:scaleType="fitXY" 
       android:src="@drawable/not_found" /> 
     </android.support.v7.widget.CardView> 

     <TextView 
      android:id="@+id/tv_movie_title" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="70dp" 
      android:layout_marginStart="10dp" 
      android:padding="@dimen/poster_padding" 
      android:textAppearance="?android:textAppearanceLarge" 
      android:textColor="@android:color/black" 
      android:textStyle="bold" 
      app:layout_constraintLeft_toRightOf="@+id/cv_poster_image" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="@+id/cv_poster_image" 
      tools:text="Spider Man and Iron Man" /> 


     <TextView 
      android:id="@+id/tv_release_date" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:drawablePadding="@dimen/poster_padding" 
      android:drawableStart="@drawable/ic_date_range_black_24dp" 
      android:gravity="start" 
      android:padding="@dimen/poster_padding" 
      android:textAppearance="?android:textAppearanceSmall" 
      android:textColor="@android:color/black" 
      app:layout_constraintLeft_toLeftOf="@+id/tv_movie_title" 
      app:layout_constraintTop_toBottomOf="@+id/tv_movie_title" 
      tools:text="March, 2017" /> 

     <TextView 
      android:id="@+id/tv_rating" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:drawablePadding="@dimen/poster_padding" 
      android:drawableStart="@drawable/ic_star_black_24dp" 
      android:gravity="start" 
      android:padding="@dimen/poster_padding" 
      android:textAppearance="?android:textAppearanceSmall" 
      android:textColor="@android:color/black" 
      app:layout_constraintLeft_toLeftOf="@+id/tv_release_date" 
      app:layout_constraintTop_toBottomOf="@+id/tv_release_date" 
      tools:text="7.1" /> 

     <TextView 
      android:id="@+id/tv_genre" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:padding="@dimen/poster_padding" 
      android:textAppearance="?android:textAppearanceSmall" 
      android:textColor="@android:color/black" 
      android:textStyle="italic" 
      app:layout_constraintLeft_toLeftOf="@+id/tv_rating" 
      app:layout_constraintTop_toBottomOf="@+id/tv_rating" 
      tools:text="Horror | Comedy | Drama" /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/sliding_tabs" 
      style="@style/CategoryTab" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="10dp" 
      android:layout_marginStart="10dp" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/cv_poster_image" 
      app:tabGravity="fill" /> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/viewPager" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="10dp" 
      android:layout_marginStart="10dp" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toBottomOf="@+id/sliding_tabs" /> 

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

Innerhalb der movie_details.xml Aktivität der "viewPager" ist, wo ich die RecyclerView bin Laden.

Es ist eine einfache RecyclerView Ich habe den Code für den Adapter und den RecyclerView unten hinzugefügt.

movie_trailers_fragment.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rv_movie_trailer_list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

Unten finden Sie das Layout der einzelnen Elemente in der RecyclerView.

movie_trailer_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="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:elevation="@dimen/card_elevation" 
    card_view:cardCornerRadius="8dp" 
    card_view:cardUseCompatPadding="true"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <ImageView 
      android:id="@+id/iv_trailer_poster" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:contentDescription="@string/str_trailer_poster" 
      android:scaleType="fitXY" 
      android:src="@drawable/not_found" /> 

     <TextView 
      android:id="@+id/tv_trailer_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:padding="@dimen/detail_activity_text_padding" 
      android:textAppearance="?android:textAppearanceSmall" 
      android:textColor="@android:color/black" 
      tools:text="This Trailer Is Awesome" /> 

    </LinearLayout> 

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

Unten ist der Code für die Adapterklasse.

TrailerAdapter.java

public class MovieTrailersFragment extends Fragment { 
    public static final String MOVIE_TRAILERS_KEY = "trailer"; 

    public MovieTrailersFragment() { 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.movie_trailers_fragment, container, false); 
     savedInstanceState = this.getArguments(); 
     List<MovieTrailer> movieTrailerList = (List<MovieTrailer>) savedInstanceState.getSerializable(MOVIE_TRAILERS_KEY); 
     RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.rv_movie_trailer_list); 
     TrailerAdapter trailerAdapter = new TrailerAdapter(view.getContext()); 
     LinearLayoutManager linearLayoutManager = new LinearLayoutManager(view.getContext(),LinearLayoutManager.VERTICAL,false); 
     recyclerView.setLayoutManager(linearLayoutManager); 
     recyclerView.setNestedScrollingEnabled(true); 
     recyclerView.setHasFixedSize(true); 
     recyclerView.setItemAnimator(new DefaultItemAnimator()); 
     recyclerView.setAdapter(trailerAdapter); 
     trailerAdapter.prepareMovieTrailers(movieTrailerList); 
     return view; 
    } 

} 
+0

haben Sie keine Lösung für Ihr Problem gefunden? Ich stoße auf dasselbe Problem. –

+0

Yup Ich musste TabLayout und ViewPager in einem separaten LinearLayout trennen und dann funktionierte es einwandfrei. –

+0

Fügen Sie Ihrem RecylearView einen Balg-Padding hinzu. Dann wird der letzte Punkt angezeigt. Hoffe das wird Ihr Problem lösen. –

Antwort

0

Ich hatte das TabLayout und ViewPager in einem separaten Linearlayout zu trennen und es funktionierte dann richtig.

Unten ist das modifizierte Layout als Referenz: nur

<?xml version="1.0" encoding="utf-8"?> 
<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="match_parent" 
    android:orientation="vertical"> 

    <android.support.constraint.ConstraintLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.CardView 
      android:id="@+id/cv_poster_image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginStart="10dp" 
      android:layout_marginTop="10dp" 
      android:elevation="@dimen/card_elevation" 
      app:cardCornerRadius="8dp" 
      app:cardUseCompatPadding="true" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintTop_toTopOf="parent"> 

      <ImageView 
       android:id="@+id/iv_movie_poster" 
       android:layout_width="150dp" 
       android:layout_height="200dp" 
       android:contentDescription="@string/str_movie_poster" 
       android:padding="@dimen/poster_padding" 
       android:scaleType="fitXY" 
       android:src="@drawable/not_found" /> 
     </android.support.v7.widget.CardView> 

     <TextView 
      android:id="@+id/tv_movie_title" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="60dp" 
      android:layout_marginStart="10dp" 
      android:padding="@dimen/poster_padding" 
      android:textAppearance="?android:textAppearanceLarge" 
      android:textColor="@android:color/black" 
      android:textStyle="bold" 
      app:layout_constraintLeft_toRightOf="@+id/cv_poster_image" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="@+id/cv_poster_image" 
      tools:text="Spider Man and Iron Man" /> 


     <TextView 
      android:id="@+id/tv_release_date" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:drawablePadding="@dimen/poster_padding" 
      android:drawableStart="@drawable/ic_date_range_black_24dp" 
      android:gravity="start|center_vertical" 
      android:padding="@dimen/poster_padding" 
      android:textAppearance="?android:textAppearanceSmall" 
      android:textColor="@android:color/black" 
      app:layout_constraintLeft_toLeftOf="@+id/tv_movie_title" 
      app:layout_constraintTop_toBottomOf="@+id/tv_movie_title" 
      tools:text="March, 2017" /> 

     <TextView 
      android:id="@+id/tv_rating" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:drawablePadding="@dimen/poster_padding" 
      android:drawableStart="@drawable/ic_star_black_24dp" 
      android:gravity="start|center_vertical" 
      android:padding="@dimen/poster_padding" 
      android:textAppearance="?android:textAppearanceSmall" 
      android:textColor="@android:color/black" 
      app:layout_constraintLeft_toLeftOf="@+id/tv_release_date" 
      app:layout_constraintTop_toBottomOf="@+id/tv_release_date" 
      tools:text="7.1" /> 

     <TextView 
      android:id="@+id/tv_genre" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="8dp" 
      android:padding="@dimen/poster_padding" 
      android:textAppearance="?android:textAppearanceSmall" 
      android:textColor="@android:color/black" 
      android:textStyle="italic" 
      app:layout_constraintLeft_toLeftOf="@+id/tv_rating" 
      app:layout_constraintTop_toBottomOf="@+id/tv_rating" 
      tools:text="Horror | Comedy | Drama" /> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab_tab_layout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/fab_margin" 
      android:layout_marginRight="10dp" 
      app:layout_constraintBottom_toBottomOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="parent" 
      app:layout_constraintVertical_bias="0.0" 
      app:srcCompat="@drawable/ic_favorite_border_black_24dp" /> 

    </android.support.constraint.ConstraintLayout> 

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

     <android.support.design.widget.TabLayout 
      android:id="@+id/sliding_tabs" 
      style="@style/CategoryTab" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="10dp" 
      android:layout_marginStart="10dp" 
      android:layout_marginTop="10dp" 
      app:tabGravity="fill" /> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/viewPager" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginEnd="10dp" 
      android:layout_marginStart="10dp" 
      android:layout_marginTop="10dp" /> 

    </LinearLayout> 

</LinearLayout> 

aktualisiert

I Fragmente verwenden so das obige Layout wird das Layout in einem FrameLayout gezeigt ist, die die NestedScrollView enthält und verwendet im Falle von Tablet-Großbildschirmen.

Der Behälter für das obige Fragment in großen Bildschirmen:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView 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:fillViewport="true" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <FrameLayout 
     android:id="@+id/detail_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</android.support.v4.widget.NestedScrollView> 
+0

Aber wo ist NestedScrollView? du benutzt es nicht mehr? –

+0

Ich benutzte Fragmente so für Tablet-Layout Ich brauche nicht die NestedScrollView nur für das Telefon-Layout. –

0

Ich denke, Sie ein Problem haben, weil Navigationsleiste Ihre App Layout überlappen. Sie müssen Ihre Navigationsleiste einrichten, werfen Hauptthema oder Aktivität Stile

+0

Kannst du mehr erklären, es funktioniert, wenn ich den Viewpager und Tablayout in einem linearen Layout getrennt habe. –

+0

1. Versuchen klar Scrollview zu verwenden, da ich Recycler Arbeit gut in Scroll-Ansicht 2. Die Überlappungsproblem auf Stile hängt wissen, weil App-Fenster unter der Navigationsleiste ist versuchen, über android suchen: windowTranslucentNavigation android: fitSystemWindows 3. Weiß ich noch nicht – user8064960

+0

Das Problem bleibt bestehen, auch wenn Sie es in einem Telefon ohne die untere Navigationsleiste ausführen, habe ich Note 5 verwendet. Und wenn ich scrollView verwende, bekomme ich den scrollenden Appbar-Effekt nicht. Mein Verständnis war die NestedScrollView ist nicht in der Lage, die Bildschirmgröße zu messen, wenn Sie eine Recycler-View in einem Viewpager verwenden. Deshalb habe ich ein lineares Layout hinzugefügt und den Viewpager getrennt. So, wie ich unten geantwortet habe. –

Verwandte Themen