为什么在抽屉布局中查看是强制缩放以填充屏幕 [英] why view in drawerlayout is force scale to fill screen

查看:61
本文介绍了为什么在抽屉布局中查看是强制缩放以填充屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的测试代码:

<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大小

how to make TextView show 100dp size

更新

我可以使用以下代码对其进行修复:

i can fix it with following code:

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

但是我希望没有CoordinatorLayout的方法,这太麻烦了

but i hope a way without CoordinatorLayout, it's too trouble

推荐答案

DrawerLayout 的第一个子元素 View 是主要内容 View ,无论您在其上设置了什么布局属性,都将对其进行布局以填充 DrawerLayout .

The first child View of a DrawerLayout is the main content View, and it will be laid out to fill the DrawerLayout regardless of the layout attributes you set on it.

如果您希望 TextView 为您设置的大小,则需要将其包装在另一个 ViewGroup 中,该内容作为主要内容 View .例如:

If you want your TextView to be the size you set, you need to wrap it in another ViewGroup that acts as the main content View. For example:

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

这篇关于为什么在抽屉布局中查看是强制缩放以填充屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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