如何并排放置两个textview并使用50%宽度的屏幕

Si8*_*Si8 3 java android textview

我有以下代码,它有4行并排的2个文本视图:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp"
    android:layout_weight="1.1"
    android:gravity="center"
    android:weightSum="4" >
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center" >
        <TextView
            android:id="@+id/tvCodeNameDetail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="cnsdsdsf:"
            android:layout_weight="1"
            android:gravity="center"
            android:background="#ff0000" />
        <TextView
            android:id="@+id/tvCodeName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:layout_weight="1"
            android:gravity="center"
            android:background="#00FF00" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center" >
        <TextView
            android:id="@+id/tvVersionDetail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="vnddf: "
            android:layout_weight="1"
            android:gravity="center"
            android:background="#00ff00" />
        <TextView
            android:id="@+id/tvVersion"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:layout_weight="1"
            android:gravity="center"
            android:background="#ff0000" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center" >
        <TextView
            android:id="@+id/tvReleaseDetail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="rdsdfsdfsfsdf: "
            android:layout_weight="1"
            android:gravity="center"
            android:background="#FF0000" />
        <TextView
            android:id="@+id/tvRelease"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:layout_weight="1"
            android:gravity="center"
            android:background="#00FF00" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center" >
        <TextView
            android:id="@+id/tvAPIDetail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="apdd: "
            android:layout_weight="1"
            android:gravity="center"
            android:background="#00ff00" />
        <TextView
            android:id="@+id/tvAPI"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:layout_weight="1"
            android:gravity="center"
            android:background="#ff0000" />
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

它显示以下内容:

在此输入图像描述

如何修改代码使其总是50%/ 50%没有文本视图中的文本?

cod*_*gic 16

改变widthTextView的两个0dp而不是wrap_content

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:gravity="center" >
    <TextView
        android:id="@+id/tvCodeNameDetail"
        android:layout_width="0dp"              <!-- here -->
        android:layout_height="wrap_content"
        android:text="cnsdsdsf:"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#ff0000" />
    <TextView
        android:id="@+id/tvCodeName"
        android:layout_width="0dp"              <!-- and here -->
        android:layout_height="wrap_content"
        android:text="TextView"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#00FF00" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

当使用weighthorizontal LinearLayout你需要有一个width0dp.同样,在一个vertical LinearLayout,你会想height0dp.