对于 android 内容视图,我有一个垂直线性布局,其中有一些文本视图,其中有一些线来划分和分隔垂直元素,这工作正常,xml 如下。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/A" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/B" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/C" />
</LinearLayout>
<View
android:background="#ffffff"
android:layout_width = "fill_parent"
android:layout_height="1dip"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/D" />
<View
android:background="#ffffff"
android:layout_width = "fill_parent"
android:layout_height="1dip" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/E" />
</LinearLayout>
现在我想在带有字符串 A/B/C 的嵌套文本视图中水平放置的文本视图之间添加垂直分隔线。当我尝试通过添加硬编码宽度视图来执行此操作时,该线跨越父线性布局的整个高度。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/A" />
<!--the vertical line separator-->
<View
android:background="#ffffff"
android:layout_width = "1dip"
android:layout_height="fill_parent" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/B" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="@string/C" />
</LinearLayout>
<View
android:background="#ffffff"
android:layout_width = "fill_parent"
android:layout_height="1dip"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/D" />
<View
android:background="#ffffff"
android:layout_width = "fill_parent"
android:layout_height="1dip" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/E" />
</LinearLayout>
对于这个垂直分隔符视图,我尝试使用android:layout_height="wrap_content"/>
相反,但呈现相同的结果。
有没有办法在这里有一个垂直分隔符,通过引入垂直线来分隔文本视图来保留高度?或者我必须选择不同的布局?
另一种选择可能是包括android:layout_margin
(或单独layout_marginTop
and layout_marginBottom
) 在绘制的垂直线的顶部和底部与相应的水平边缘之间创建一个空间LinearLayout.
除此之外,我可能会尝试RelativeLayout,
并调整垂直线视图,使其顶部和底部与相邻的其中之一对齐TextViews.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)