gpt4 book ai didi

android - match_parent 不适用于 CoordinatorLayout

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:15:40 25 4
gpt4 key购买 nike

我使用 Android 设计支持库 (com.android.support:appcompat-v7:22.2.0),并且我有一个 LinearLayoutCoordinatorLayout像这样:

<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" />

在代码中我改变了背景颜色,我希望 BG 应该填满显示器(因为我在 layout_width 和 layout_height 中使用了 match_parent)但是我得到了这样的 BG 颜色:

enter image description here

看起来它显示了 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 下正常工作.现在,当我将 fragment 添加到 LinearLayout 时,布局对齐方式(在 fragment 布局中)与我的预期不同。使用比率或相对值的一切都不起作用。

谢谢

最佳答案

行为 appbar_scrolling_view_behavior 应该应用于实现 ScrollingViewView .

如果您不需要在滚动主要内容时自动隐藏 ToolbarLayout 或使用 RecyclerView 而不是 LinearLayout

关于android - match_parent 不适用于 CoordinatorLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31519574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com