2015-12-11 8 views
1

Я использовал CoordinatorLayout в моем XML-файле вместе с разворачиванием макета панели инструментов и вложенным видом прокрутки. Все установлено. Он показывает красивую анимацию панели инструментов, когда вложенные прокрутки просматриваются с прокруткой вниз. Но я столкнулся с одной проблемой. Всякий раз, когда вложенное представление прокрутки имеет меньше элементов внутри, координатный макет прокручивается без необходимости, оставляя пустое место внизу.Координатная компоновка оставляет пустое место внизу

У меня много googled, чтобы найти решение. В некоторых сообщениях предлагается использовать android:fitsSystemWindows="true" для компоновки макета и макета панели приложений. Я тоже это сделал, но это не помогло мне решить мою проблему. Whatsapp изящно обрабатывать этот случай:

enter image description here

Любая помощь будет оценена. Заранее спасибо!! Вот мой XML: `

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="256dp" 
    android:fitsSystemWindows="true" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

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

     <ImageView 
      android:id="@+id/backdrop" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="fitXY" 
      android:src="@drawable/img" 
      app:layout_collapseMode="parallax" /> 

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

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

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

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

     <android.support.v7.widget.CardView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/card_margin"> 

      <LinearLayout 
       style="@style/Widget.CardContent" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Info" 
        android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/cheese_ipsum" /> 

      </LinearLayout> 

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

     <android.support.v7.widget.CardView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:visibility="visible" 
      android:layout_marginBottom="@dimen/card_margin" 
      android:layout_marginLeft="@dimen/card_margin" 
      android:layout_marginRight="@dimen/card_margin"> 

      <LinearLayout 
       style="@style/Widget.CardContent" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Friends" 
        android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/cheese_ipsum" /> 

      </LinearLayout> 

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

     <android.support.v7.widget.CardView 
      android:id="@+id/thirdCard" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:visibility="invisible" 
      android:layout_marginBottom="@dimen/card_margin" 
      android:layout_marginLeft="@dimen/card_margin" 
      android:layout_marginRight="@dimen/card_margin"> 

      <LinearLayout 
       style="@style/Widget.CardContent" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Related" 
        android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/cheese_ipsum" /> 

      </LinearLayout> 

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

    </LinearLayout> 

</android.support.v4.widget.NestedScrollView> 
<!--app:layout_behavior="fabsample.extentia.com.fabsampleapp.ScrollAwareFabBehavour"--> 

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

`

+0

Вы должны поделились своим 'xml' для этого. Но я думаю, что вы должны изучить атрибуты отступов и полей, включая представление, содержащее статус, уведомление и телефонную карточку. –

+0

@HammadMukhtar, вы можете увидеть выше xml, я не установил прописку для вложенного просмотра прокрутки. – adi

+0

удалить 'android: layout_marginBottom =" @ dimen/card_margin "из третьего CardView. –

ответ

0

Попробуйте это,

<android.support.v7.widget.CardView 
     android:id="@+id/thirdCard" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:visibility="invisible" 
     android:layout_marginLeft="@dimen/card_margin" 
     android:layout_marginRight="@dimen/card_margin">