gpt4 book ai didi

android - 工具栏填满整个屏幕

转载 作者:太空狗 更新时间:2023-10-29 16:31:02 26 4
gpt4 key购买 nike

我不熟悉抽屉布局和 fragment 的使用。

我使用了 tutorial关于使用 DrawerLayout 创建 Activity 。它在 getActionBar() 上给了我一个空指针,所以我添加了 a toolbar到主要 Activity 并使用 getSupportActionBar() 代替。

现在看起来工具栏充满了整个屏幕,因为标题在屏幕中间,工具栏的背景也在整个屏幕上。这是 xml 代码:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Toolbar -->
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" />
<!-- The navigation drawer -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFFFFF"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>

我试过用 56dp 替换 layout_height 并且我试过制作一个单独的布局文件,其中包含工具栏并将其包含到这个 xml 中,但这没有用。

为什么我的工具栏会填满整个屏幕?

最佳答案

DrawerLayout 需要 2 个 View 。你提供 3 个。

第一个 View 是“背景”。它是屏幕的内容。第二个 View ,抽屉,应该以动画方式进出。

您提供了 3 个 View 。所以您的工具栏就是“内容”——因此是全屏,而您的抽屉就是您的实际内容。

要解决您的问题,请尝试以下操作:

<DrawerLayout>

<!-- The main content view -->
<LinearLayout>
<Toolbar/>
<FrameLayout
android:id="@+id/content_frame"/>
</LinearLayout>

<!-- The navigation drawer -->
<ListView/>
</DrawerLayout>

关于android - 工具栏填满整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38805119/

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