2014-10-01 83 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)

您可能还需要在垂直线上添加一些顶部和底部边距,并使背景颜色变为透明而不是白色(因此您也可以在深色容器背景颜色上使用它)。