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
?“你没有那个布局的抽屉。”米肯。这只是一个简单的例子来重现我的问题,我需要真实代码中的抽屉布局