Android 线性布局不';看不见

Android 线性布局不';看不见,android,xml-layout,Android,Xml Layout,我使用的是线性布局,它不会显示所有视图 这是xml代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="160dp" android:layout_height="wrap_content" android:orientat

我使用的是
线性布局
,它不会显示所有视图

这是xml代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="160dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    tools:context="de.schumann_connection.yahtzee.DescriptionColumnFragment">

    <View
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:background="#FF000000" />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        tools:context="de.schumann_connection.yahtzee.DescriptionColumnFragment">

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#FF000000" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="43dp"
            android:text=""/>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#FF000000" />
    </LinearLayout>

    <View
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:background="#FF000000" />
</LinearLayout>

包含的控件多得多,但这足以说明问题所在

这应该画一个黑色的矩形。但右边的垂直线丢失了。
为什么?

这是做你想做的事情的错误方式。您想要一个周围有黑色背景的文本视图吗?只需在文本视图的四面添加填充,并设置背景色。

这是错误的做法。您想要一个周围有黑色背景的文本视图吗?只需在文本视图的四周添加填充,并设置背景色。

我认为“视图”甚至不是一个对象

看起来您更喜欢相对视图,或者文本视图或图像视图

无论如何,它没有出现的原因是因为它不存在。

我甚至不认为“视图”是一个对象

看起来您更喜欢相对视图,或者文本视图或图像视图


无论如何,它没有出现的原因是因为它不存在。

只需为内部线性布局添加权重即可
android:layout\u width=“0dp”
android:layout\u weight=“1”



只需将权重添加到内部线性布局
android:layout\u width=“0dp”
android:layout\u weight=“1”




您已将查看背景色设置为透明“android:background=“#FF000000”替换颜色代码“android:background=“#FF0000”

您已将查看背景色设置为透明“android:background=“#FF000000”替换颜色代码“android:background=“#FF0000”

不,这不是我要做的。里面还有一些控件。我尝试创建一些片段,并尝试将它们添加到表中,但我无法在运行时创建表并添加一些列。您尝试过TableView吗?在这里,您可能过于简化了示例。我将尝试使用TableView-thx。我补充了一句话,其中包含了更多的控件,但这足以说明问题所在。我想说的是有更多的控制。不,这不是我想要做的。里面还有一些控件。我尝试创建一些片段,并尝试将它们添加到表中,但我无法在运行时创建表并添加一些列。您尝试过TableView吗?在这里,您可能过于简化了示例。我将尝试使用TableView-thx。我补充了一句话,其中包含了更多的控件,但这足以说明问题所在。以明确包含更多控件。视图是一个对象。然而,使用一个作为间隔通常意味着作者做了错事,这是一种非常低效的做事方式。3年或4年前,当人们在平台上加速时,它被更频繁地使用。@Gabeschen我很确定我做错了什么。问题是我是一名C#开发者,但这是我试图创建的第一个android程序。@Verarind抱歉,这不是挖苦。很多旧答案都会使用这样的视图。这是一种行之有效的方法,但随着时间的推移,人们发现这是一种不好的做法。尽管如此,您有时仍会在快速而肮脏的代码中看到它。视图是一个对象。然而,使用一个作为间隔通常意味着作者做了错事,这是一种非常低效的做事方式。3年或4年前,当人们在平台上加速时,它被更频繁地使用。@Gabeschen我很确定我做错了什么。问题是我是一名C#开发者,但这是我试图创建的第一个android程序。@Verarind抱歉,这不是挖苦。很多旧答案都会使用这样的视图。这是一种行之有效的方法,但随着时间的推移,人们发现这是一种不好的做法。但有时你仍然会在快速和肮脏的代码中看到它。为什么所有其他行都按预期显示?我不确定,我猜,在design has view中,宽度为1dp,透明度为1dp,在该空间中(1dp)其父背景色将可见,为什么所有其他行都按预期显示?我不确定,我猜,在design has view中,宽度为1dp,具有透明度,在该空间中(1dp)其父级背景颜色将可见您在android中使用所有宽度:layout\u width=“match\u parent”使用权重可以避免问题;)如果您认为答案合适,请标记为已解决;)目前我不明白体重的含义,但我会寻找更多的信息。尽管如此,我仍然认为我的方式不是去做我想做的事情的方式。我将尝试一个TableView——希望它是我所需要的。当然,这不是最好的方法,使用自定义可绘制xml或九补丁png更好,这是建议您在android上使用全宽度:layout\u width=“match\u parent”使用权重可以避免问题;)如果您认为答案合适,请标记为已解决;)目前我不明白体重的含义,但我会寻找更多的信息。尽管如此,我仍然认为我的方式不是去做我想做的事情的方式。我会尝试一个TableView——希望它是我所需要的。当然,这不是最好的方法,使用自定义可绘制xml或九补丁png更好,这是建议的
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

<View
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:background="#FF000000" />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#FF000000" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="43dp"
        android:text="Hola"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#FF000000" />
</LinearLayout>

<View
    android:layout_width="1dp"
    android:layout_marginRight="5dp"
    android:layout_height="match_parent"
    android:background="#FF000000" />