2015-10-23 155 views
1

這是在我的活動原始佈局:NestedScrollView充滿全屏

<?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="com.example.myapp.MyActivity"> 
    <include layout="@layout/content_my_activity"/> 
    <android.support.design.widget.AppBarLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" 
      app:layout_scrollFlags="snap"/> 
    </android.support.design.widget.AppBarLayout> 
</android.support.design.widget.CoordinatorLayout> 

它看起來不錯:

enter image description here

內容佈局文件包含一個TableLayout。

由於內容可能很長,我加了NestedScrollView:

<?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="com.example.myapp.MyActivity"> 
    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <include layout="@layout/content_my_activity"/> 
    </android.support.v4.widget.NestedScrollView> 
    <android.support.design.widget.AppBarLayout 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" 
      app:layout_scrollFlags="snap"/> 
    </android.support.design.widget.AppBarLayout> 
</android.support.design.widget.CoordinatorLayout> 

現在佈局填滿整個屏幕和標題是AppBar背後

enter image description here

我應該修改什麼?

回答

3

嵌套的滾動視圖被告知在寬度和高度上匹配父項,並且通常ActionBar保留空間並相應地將內容壓下,但與ToolBar匹配的新AppBarLayout不會執行此操作。這意味着其他佈局需要被告知AppBarLayout的存在。

嘗試將此添加到您的NestedScrollView

app:layout_behavior="@string/appbar_scrolling_view_behavior" 
+0

是的,這就是問題所在,並表示屬性解決的問題。這應該在開發人員指南中更清楚地提到:) – Nestor