why view in drawerlayout is force scale to fill screen

前端 未结 1 1572
迷失自我
迷失自我 2021-01-26 03:57

here is my test code:



        
相关标签:
1条回答
  • 2021-01-26 04:30

    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.

    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>
    
    0 讨论(0)
提交回复
热议问题