3

对于android内容视图,我有一些垂直线性布局,其中包含一些textviews,用于划分和分隔垂直元素,此工作正常,xml位于下方。Android:在垂直线性布局中嵌入水平线性布局的文本视图之间放置垂直分隔线/分隔线?

<?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"/>代替,但同样的结果被呈现。

有没有办法在这里有一个垂直分隔符,其中的高度保存,并引入一个垂直线来分隔textviews?或者我必须选择不同的布局?

+0

为什么不使用“match_parent”作为高度属性? – Guardanis

回答

1

你必须给一个固定高度要么你的LinearLayout或您的垂直分隔符

+0

是的,这是一种解决方案,但它不适用于更改文字大小。我希望有一个更优雅的解决方案。我把20dip,并且是有效的。但是我担心硬编码高度可能会导致以后出现问题。 – Vass

3

另一种选择可能是包括机器人:layout_margin(或单独layout_marginTop和layout_marginBottom)创建顶部之间的空间以及绘制的垂直线的底部和线性布局的相应水平边缘。

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