2014-10-01 49 views
0

我想在ImageView之間獲得一條垂直線以展示流。垂直線和圓形視圖

這是我想實現,

enter image description here

這是我現在有

enter image description here

背景

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:left="44dp"> 
     <shape android:shape="rectangle"> 
      <solid android:color="@android:color/darker_gray" /> 
      <padding android:left="1dp" /> 
     </shape> 
    </item> 
    <item android:left="44dp"> 
     <shape android:shape="rectangle"> 
      <solid android:color="@android:color/white" /> 
     </shape> 
    </item> 
</layer-list> 

項目佈局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/progress_item_bg" 
    android:orientation="horizontal" 
    android:padding="10dp"> 

    <ImageView 
     android:src="@drawable/circle" 
     android:layout_weight="20" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" /> 
    <TextView 
     android:id="@+id/label" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="80" 
     android:gravity="center_vertical" 
     android:paddingLeft="10dp" 
     android:paddingStart="10dp" 
     android:text="Group" /> 


</LinearLayout> 

有沒有更好的方法來做到這一點?

回答

1

Is there a better way to do this

您可以使用一個TextView包括左側圖片,並保存自己查看每一行只需使用一種化合物可繪製:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/progress_item_bg" 
    android:padding="10dp" 
    > 
    <TextView 
     android:id="@+id/label" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:drawableLeft="@drawable/circle" 
     android:drawablePadding="8dp" 
     android:gravity="center_vertical" 
     android:paddingLeft="10dp" 
     android:paddingStart="10dp" 
     android:text="Group" 
    /> 
</RelativeLayout> 

要設置通過代碼,使用setCompundDrawablesWithIntrinsicBounds(提拉): int,int,int)

您可能還需要在垂直線上添加一些頂部和底部邊距,並使背景顏色變爲透明而不是白色(因此您也可以在深色容器背景顏色上使用它)。