3

对于 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"/>改用,但显示的结果相同。

有没有办法在此处设置垂直分隔符,通过引入垂直线来分隔文本视图来保留高度?还是我必须选择不同的布局?

4

2 回答 2

3

另一种选择可能是包括android:layout_margin(或单独的layout_marginTopand layout_marginBottom)以在绘制的垂直线的顶部和底部与相应的水平边缘之间创建一个空间LinearLayout.

除此之外,我可能会尝试 aRelativeLayout,并调整您的垂直线视图以将其顶部和底部与相邻的一个对齐TextViews.

于 2013-03-18T15:29:53.040 回答
1

您必须为LinearLayoutVertical Seperator提供固定高度

于 2012-10-10T10:32:14.983 回答