layout_weight:不显示文本

时间:2015-07-04 20:26:51

标签: android android-layout-weight

我试图创建一个允许水平文本具有相同空间的界面,使用layout_weight进行响应

所以,我尝试了下面的代码

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:background="@android:color/darker_gray">

<TextView
    android:gravity="center"
    android:text="Guest List"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="24sp"
    android:background="@android:color/holo_blue_bright"/>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white">
    <TextView
        android:text="Kunal"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textSize="24sp"/>


    <TextView
        android:text="Darling"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textSize="24sp"/>

    <TextView
        android:text="Shocker"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textSize="24sp"/>
</LinearLayout>

然而,所有文本都消失了。 那么,有谁能请向我解释发生了什么以及如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

试试这个,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/darker_gray"
    android:gravity="center_vertical"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_blue_bright"
        android:gravity="center"
        android:text="Guest List"
        android:textSize="24sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Kunal"
            android:textSize="24sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Darling"
            android:textSize="24sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Shocker"
            android:textSize="24sp" />
    </LinearLayout>

</LinearLayout>

答案 1 :(得分:0)

在第二个LinearLayout中使用白色背景颜色,您可能会尝试在白色文本上看到白色。

我会尝试添加TextViews:

        android:textColor="@android:color/black"
相关问题