Wat*_*n.s 11 android android-layout androiddesignsupport
我用的是Android设计支持库(com.android.support:appcompat-v7:22.2.0),我有一个LinearLayout在CoordinatorLayout这样的:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<!-- Content -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#44ff44"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yo Yo"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yo Yo"
/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:itemIconTint="@color/nav_item_icon_tint_color"
app:itemTextColor="@color/nav_item_text_color"
app:menu="@menu/navigation_drawer_items" />
Run Code Online (Sandbox Code Playgroud)
在代码中我改变了背景颜色,我希望BG应该填满显示器上的所有内容(因为我在layout_width和layout_height中使用match_parent)但是我得到了这样的BG颜色:

看起来它显示的wrap_content不仅仅是使用match_parent.我尝试layout_weight在LinearLayout中使用layout_centerInParent它并且它也不起作用.
我做错了什么?或者它是API错误?
更新:**
为了满足我可以使用的背景android:layout_gravity="fill_vertical"(建议@Abdullah).但是我的另一个点,这个问题是我想要的match_parent,layout_weight在的LinearLayout或layout_centerInParent和其他相对值中的RelativeLayout到下正常工作CoordinatorLayout.现在,当我将片段添加到LinearLayout时,布局对齐(在片段布局中)与我的期望不同.使用比率或相对值的一切都不起作用.
谢谢
该行为appbar_scrolling_view_behavior应该应用于该ViewImplement ScrollingView。
如果您不需要ToolbarLayout在滚动主要内容时自动隐藏 或使用 aRecyclerView代替 ,请删除该行为LinearLayout。