簡體   English   中英

Android:將文本視圖之間的垂直分隔線/分隔線放在嵌套在垂直線性布局中的水平線性布局中?

[英]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_marginToplayout_marginBottom ),以在繪制的垂直線的頂部和底部與LinearLayout.的相應水平邊之間創建一個空格LinearLayout.

除此之外,我可能會嘗試使用RelativeLayout,並調整垂直線視圖以使其頂部和底部與其中一個相鄰的TextViews.對齊TextViews.

您必須為LinearLayoutVertical Seperator提供修復高度

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM