i need to add a line of dots to my layout like this

enter image description here

this is my layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/deals_list_item_bckg"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/dealImg"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:scaleType="fitXY"
        android:src="@drawable/deals_list_img" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/dealDescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="5dp"
            android:maxLines="3"
            android:text="Lorem Ipsum dolor sit amet dolor sed a ite amkt Lantin dolor latim dk kuitshen sed iditur anet" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/dealNewPrice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_marginRight="5dp"
                android:text="1248$"
                android:textColor="@color/deals_list_new_price"
                android:textSize="18sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/dealOldPrice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginRight="15dp"
                android:layout_toLeftOf="@+id/dealNewPrice"
                android:text="2500$"
                android:textColor="@color/deals_list_old_price"
                android:textSize="15sp" />
        </RelativeLayout>
    </LinearLayout>

</LinearLayout>

in which way i can do this thing i also try using a ShapeDrawable but still not understand how it works i need an example to see how it work and how do this in may layout between description textview and prices textviews

有帮助吗?

解决方案

Try this

Note: in Higher versions, without android:layerType attribute will not work. Now add android:layerType attribute with software value as below

android:layerType="software"

For more details see LAYER_TYPE_SOFTWARE

Your updated layout should be as below

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/rounded_edge"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/dealImg"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/dealDescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="5dp"
            android:maxLines="3"
            android:text="Lorem Ipsum dolor sit amet dolor sed a ite amkt Lantin dolor latim dk kuitshen sed iditur anet" />

        <View
            android:layout_width="match_parent"
            android:layout_height="5dip"
            android:background="@drawable/dash_line"
            android:layerType="software"
            android:orientation="vertical" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/dealNewPrice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_marginRight="5dp"
                android:text="1248$"
                android:textColor="@color/scoreColor"
                android:textSize="18sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/dealOldPrice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginRight="15dp"
                android:layout_toLeftOf="@+id/dealNewPrice"
                android:text="2500$"
                android:textColor="@color/scoreColor"
                android:textSize="15sp" />
        </RelativeLayout>
    </LinearLayout>

</LinearLayout>

dash line is dash_line.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="line" >

       <solid android:color="#fdfdfd" >
        </solid>

      <stroke
          android:dashGap="5px"
          android:dashWidth="5px"
          android:width="2dp"
          android:color="@color/scoreColor" >
      </stroke>

</shape>

其他提示

drawable/dot_repeated.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/dot"
    android:tileMode="repeat" />

layout

...

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/dealDescription"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        android:maxLines="3"
        android:text="Lorem Ipsum dolor sit amet dolor sed a ite amkt Lantin dolor latim dk kuitshen sed iditur anet" />

    <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/dot_height"
        android:background="@drawable/dot_repeated"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

...
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top