Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为什么抽屉布局中的视图是强制比例填充屏幕_Android_User Interface - Fatal编程技术网

Android 为什么抽屉布局中的视图是强制比例填充屏幕

Android 为什么抽屉布局中的视图是强制比例填充屏幕,android,user-interface,Android,User Interface,以下是我的测试代码: <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height=

以下是我的测试代码:

<android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="ro.rotry.NdInnerViewAutoFillScreen">
    <TextView android:text="in drawerlayout" android:textColor="@android:color/white" android:background="@android:color/black" android:layout_width="100dp" android:layout_height="100dp"/>
</android.support.v4.widget.DrawerLayout>

如何使TextView显示100dp大小

更新

我可以用以下代码修复它:

  <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent"
                                                     android:layout_height="match_parent">
        <TextView android:text="in coordinator" android:textColor="@android:color/white" android:background="@android:color/black" android:layout_width="100dp" android:layout_height="100dp"/>
    </android.support.design.widget.CoordinatorLayout>


但是我希望没有协调布局的方法,这太麻烦了,
抽屉布局的第一个子
视图
是主要内容
视图
,它将被布置成填充
抽屉布局
,而不管您在其上设置了什么布局属性

如果希望您的
文本视图
为您设置的大小,则需要将其包装在另一个
视图组
中,该组作为主要内容
视图
。例如:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="ro.rotry.NdInnerViewAutoFillScreen">

    <RelativeLayout android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView android:text="in drawerlayout"
            android:textColor="@android:color/white"
            android:background="@android:color/black"
            android:layout_centerInParent="true"
            android:layout_width="100dp"
            android:layout_height="100dp"/>

    </RelativeLayout>

    <View android:id="@+id/drawer"
        ... />

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

抽屉布局的第一个子
视图
是主要内容
视图
,它的布局将填充抽屉布局
,而与您在其上设置的布局属性无关

如果希望您的
文本视图
为您设置的大小,则需要将其包装在另一个
视图组
中,该组作为主要内容
视图
。例如:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="ro.rotry.NdInnerViewAutoFillScreen">

    <RelativeLayout android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView android:text="in drawerlayout"
            android:textColor="@android:color/white"
            android:background="@android:color/black"
            android:layout_centerInParent="true"
            android:layout_width="100dp"
            android:layout_height="100dp"/>

    </RelativeLayout>

    <View android:id="@+id/drawer"
        ... />

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


您真的需要抽屉布局吗?“你没有那个布局的抽屉。”米肯。这只是一个简单的例子来重现我的问题,我需要真实代码中的抽屉布局你真的需要
DrawerLayout
?“你没有那个布局的抽屉。”米肯。这只是一个简单的例子来重现我的问题,我需要真实代码中的抽屉布局