7

Zauważyłem, że zawartość w NestedSCrollView wewnątrz elementu CoordinatorLayout zawsze wyrównuje się na dole, jeśli nie wypełnia całego ekranu. Jak mogę to naprawić?Android NestedScrollView wyrównaj zawartość na górze

Mój kod:

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

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

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

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

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

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

      <android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:layout_marginTop="10dp" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       card_view:cardBackgroundColor="@color/white" 
       card_view:cardElevation="2sp" 
       card_view:cardUseCompatPadding="true"> 

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

      <ListView 
       android:layout_height="match_parent" 
       android:layout_width="match_parent" 
       android:layout_marginTop="10dp" 
       android:divider="@color/black_200" 
       android:dividerHeight="-7dp" 
       android:listSelector="@android:color/transparent" 
       android:cacheColorHint="@android:color/transparent" /> 

     </LinearLayout> 

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

    <android.support.design.widget.FloatingActionButton 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:src="@drawable/ic_navigate" 
     android:layout_margin="16dp" 
     app:backgroundTint="@color/accent_yellow" 
     app:borderWidth="0dp" 
     app:elevation="8dp" 
     app:pressedTranslationZ="12dp" 
     app:fabSize="normal" 
     app:rippleColor="@color/accent_dark_yellow" 
     app:layout_anchor="@id/appbar" 
     app:layout_anchorGravity="bottom|right|end"/> 

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

Jak widać, CardView wewnątrz NestedScrollView jest 200dp wysoki i wyrównany na dole.

Odpowiedz

16

użyć następującego obiektu android.support.v4.widget.NestedScrollView

android:layout_gravity="fill_vertical" 
0

Należy ustawić prawidłową kotwicę.

Zmień * Android: layout_gravity = "top" * do aplikacji: layout_anchorGravity = "top | start"

+0

Niestety, nie naprawić go. Jak mam z niego korzystać? Po prostu użyj aplikacji: layout_anchorGravity = "top" zamiast android: layout_gravity = "top"? Ponadto powinienem umieścić to w LinearLayout? – qwertz

+1

Nowa modyfikacja go nie naprawiła albo: – qwertz

+0

czy umieściłeś atrybuty na liniowym layoucie lub na nestedlayout? – EE66

Powiązane problemy