[英]Android: Putting a vertical divider/separator line between textviews in a horizontal linear layout nested in vertical linear layout?
对于一个Android内容视图,我有一个垂直linearlayout,其中一些textviews有一些分隔和分隔垂直元素的行,这个工作正常,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
和layout_marginBottom
),以在绘制的垂直线的顶部和底部与LinearLayout.
的相应水平边之间创建一个空格LinearLayout.
除此之外,我可能会尝试使用RelativeLayout,
并调整垂直线视图以使其顶部和底部与其中一个相邻的TextViews.
对齐TextViews.
您必须为LinearLayout或Vertical Seperator提供修复高度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.