Android 我的布局有问题

Android 我的布局有问题,android,xml,android-layout,android-linearlayout,Android,Xml,Android Layout,Android Linearlayout,我已经把我的观点分成5次,我想在每个隔间上放不同的东西。这就是我面临的问题 没有文本视图 使用文本视图 这是我的密码 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#add823" android:weightSum="1" android:l

我已经把我的观点分成5次,我想在每个隔间上放不同的东西。这就是我面临的问题

没有文本视图

使用文本视图

这是我的密码

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#add823"
        android:weightSum="1"
        android:layout_weight="0.5"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0.5"
            android:orientation="vertical"/>

        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="#111111"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="0.5"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_height="wrap_content"
                android:text="Power"/>
        </LinearLayout>
    </LinearLayout>

像这样更新xml,而不是
包装内容
使用
0dp
进行
线性布局
(Power text的父级)


您可以在布局包含增强文本中将wrapcontent更改为0dip

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:background="#add823"
    android:orientation="horizontal"
    android:weightSum="1">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:orientation="vertical">

    </LinearLayout>

    <View
        android:layout_width="0.5dp"
        android:layout_height="match_parent"
        android:background="#111111"></View>

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Power" />
    </LinearLayout>
</LinearLayout>

结果:


那么这里有什么问题呢?将第二个
线性布局的宽度从
wrap\u content
更改为
0dp
。谢谢。成功了
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:background="#add823"
    android:orientation="horizontal"
    android:weightSum="1">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:orientation="vertical">

    </LinearLayout>

    <View
        android:layout_width="0.5dp"
        android:layout_height="match_parent"
        android:background="#111111"></View>

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Power" />
    </LinearLayout>
</LinearLayout>