安卓:把textviews之间的垂直分隔/分隔线嵌套在垂直线性布局水平线性布局?

问题描述:

有关一个机器人的内容来看,我有一些textviews有一些行分裂和分离的垂直元素一个垂直的LinearLayout,这工作正常和XML如下。

For an android content view, I have a vertical linearlayout with some textviews that have some lines to divide and separated the vertical elements, this works fine and the xml is below.

    <?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嵌套textviews。当我尝试通过增加硬codeD宽度查看这样做,线涵盖了从父线性布局整个高度。

Now I want to add a vertical separator line between the horizontally placed text views in the nested textviews with strings A/B/C. When I try to do so by adding the hardcoded width View, the line spans the whole height from the parent linear layout.

    <?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/&GT; 代替,但相同的结果是presented。

For this vertical separator view I have tried to use android:layout_height="wrap_content"/> instead but the same result is presented.

有没有办法在这里有一个垂直分离器,在高度preserved引进一条垂直线来分隔textviews的?或者,我必须选择一个不同的布局?

Is there a way to have a vertical separator here where the height is preserved with the introduction of a vertical line to separate textviews? Or must I choose a different layout?

另一个选项可以是包括机器人:layout_margin(或分割layout_marginTop和layout_marginBottom)来创建绘制垂直线的顶部和底部与各自之间的空间线性布局的水平边缘。

Another option may be to include android:layout_margin (or separate layout_marginTop and layout_marginBottom) to create a space between the top and bottom of the drawn vertical line and the respective horizontal edges of the linear layout.

除此之外,我可能会尝试一个RelativeLayout的,和你的垂直线视图调整到其顶部和底部对齐到相邻TextViews之一。

Other than that, I might try a RelativeLayout, and have your vertical line view adjusted to align its top and bottom to one of the adjacent TextViews.