使用应用程序兼容性工具栏使用的FrameLayout [英] Using AppCompat Toolbar with FrameLayout

查看:156
本文介绍了使用应用程序兼容性工具栏使用的FrameLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的XML是这样的:

So my XML goes like this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_height="56dp"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />

    <FrameLayout
        android:id="@+id/main_frag"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- ListView here -->

</android.support.v4.widget.DrawerLayout>

这是怎么回事,即使我把我的身高明确为56dp,在工具栏行事像 match_parent 和遗嘱屏幕的整个高度?是否有这样做的更好的办法?

What is happening, even though I set my height explicitly as 56dp, the toolbar is acting like match_parent and wills the entire height of the screen? Is there a better way of doing this?

或者我应该把在一侧的布局,我的 FragementTransaction 个饱了的FrameLayout 工具栏来?这似乎不是有效的,因为我有几个的那些。

Or should I be putting the toolbar in side the layouts that my FragementTransactions fill the FrameLayout with? Which doesn't seem efficient because I have several of those.

推荐答案

DrawerLayout 有两个孩子的意见:先为主要内容,第二个抽屉:既总是被设置为 match_parent 。因此,你的工具栏的FrameLayout 应包装在垂直的LinearLayout 被设置为 match_parent 按href=\"http://stackoverflow.com/a/26440880/1676363\">典型的例子来自中的

DrawerLayout takes two children views: the first for the main content and the second for the drawer: both are always set to match_parent. Therefore your Toolbar and FrameLayout should be wrapped in a vertical LinearLayout which is set to match_parent as per the canonical example from the maker of AppCompat:

<!-- The important thing to note here is the added fitSystemWindows -->
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <!-- Your normal content view -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <!-- We use a Toolbar so that our drawer can be displayed
             in front of the action bar -->
        <android.support.v7.widget.Toolbar  
            android:id="@+id/my_toolbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:minHeight="?attr/actionBarSize"
            android:background="?attr/colorPrimary" />

        <FrameLayout
            android:id="@+id/main_frag"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

    </LinearLayout>

    <!-- Your drawer view. This can be any view, FrameLayout
         is just an example. As we have set fitSystemWindows=true
         this will be displayed under the status bar. -->
    <FrameLayout
        android:layout_width="304dp"
        android:layout_height="match_parent"
        android:layout_gravity="left|start"
        android:fitsSystemWindows="true">

        <!-- ListView here -->

    </FrameLayout>

</android.support.v4.widget.DrawerLayout>

这篇关于使用应用程序兼容性工具栏使用的FrameLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆