LinearLayout 不显示视图
LinearLayout doesn't show view
我使用的 LinearLayout
不会显示所有视图。
这是 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>
包含更多的控件,但这足以说明问题。
这应该绘制一个黑色矩形。但是缺少正确的垂直线。
为什么?
这是做你想做的事情的错误方法。你想要一个周围有黑色背景的文本视图吗?只需在您的 TextView 的所有边添加填充并设置背景颜色。
我认为 "view" 甚至不是一个对象。
看来您更愿意使用相对视图,或者可能是 textView 或 imageView。
无论如何,它没有出现的原因是因为那个东西不存在。
只给内部的LinearLayout增加权重android:layout_width="0dp"
和android:layout_weight="1"
<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" />
您已将视图背景颜色设置为透明 "android:background="#FF000000"" 替换颜色代码 "android:background="#FF0000""
我使用的 LinearLayout
不会显示所有视图。
这是 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>
包含更多的控件,但这足以说明问题。
这应该绘制一个黑色矩形。但是缺少正确的垂直线。 为什么?
这是做你想做的事情的错误方法。你想要一个周围有黑色背景的文本视图吗?只需在您的 TextView 的所有边添加填充并设置背景颜色。
我认为 "view" 甚至不是一个对象。
看来您更愿意使用相对视图,或者可能是 textView 或 imageView。
无论如何,它没有出现的原因是因为那个东西不存在。
只给内部的LinearLayout增加权重android:layout_width="0dp"
和android:layout_weight="1"
<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" />
您已将视图背景颜色设置为透明 "android:background="#FF000000"" 替换颜色代码 "android:background="#FF0000""