David Bowen David Bowen - 2 years ago 174
Android Question

Android shape -Reducing the length of the divider(line) between two items

In the image below I have two users, How do I reduce the bottom length stroke so that it only starts from "second, first".

Image of current stroke



<item>
<shape android:shape="rectangle" >
<solid android:color="#fff" />

</shape>
</item>

<item android:top="-2dp" android:right="-2dp" android:left="-2dp">
<shape>

<solid android:color="@android:color/transparent" />
<stroke
android:width="0.1dp"
android:color="#ababb2"/>
</shape>
</item>




This is the full xml. Here I have a Relative layout comprising of all the textview, and imageviews. The relative view is containing the background with the drawable shape file above.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/singleuserlist"
android:layout_width="match_parent"
android:background="@drawable/my_shape_file"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp">
<ImageView
android:id="@+id/imageview_post_userimage1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="10dp"
android:paddingRight="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Default Name"
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#191919"

android:layout_toEndOf="@+id/imageview_post_userimage1" />

<TextView
android:id="@+id/userstatus4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/username"
android:layout_below="@+id/username"
android:layout_marginTop="8dp"
android:text="Default Status"
android:textAlignment="center"
android:textSize="15sp" />

<ImageView
android:id="@+id/imageView"
android:layout_width="12dp"
android:layout_marginTop="7dp"
android:layout_height="12dp"
android:layout_marginLeft="8dp"
android:visibility="invisible"
android:background="@drawable/online_circle"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/username"
/>

<TextView
android:id="@+id/badge_notification_1"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@drawable/circle_bg"
android:gravity="center"
android:text="50"
android:textColor="#fff"
android:padding="0sp"
android:textSize="13sp"
android:textStyle="bold"
android:layout_marginEnd="21dp"
android:visibility="invisible"
android:layout_alignTop="@+id/userstatus4"
android:layout_alignParentEnd="true" />

</RelativeLayout>

Answer Source

You can change your layout to something like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/singleuserlist"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizantal">

    <ImageView
        android:id="@+id/imageview_post_userimage1"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="10dp"
        android:paddingRight="10dp" />

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/relativeLayout"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_marginBottom="5dp"
        android:background="@drawable/background">

        <TextView
            android:id="@+id/username"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toEndOf="@+id/imageview_post_userimage1"
            android:text="Default Name"
            android:textAlignment="center"
            android:textColor="#191919"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/userstatus4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/username"
            android:layout_below="@+id/username"
            android:layout_marginTop="8dp"
            android:text="Default Status"
            android:textAlignment="center"
            android:textSize="15sp" />

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="12dp"
            android:layout_height="12dp"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="7dp"
            android:layout_toEndOf="@+id/username"
            android:background="@drawable/online_circle"
            android:orientation="horizontal"
            android:visibility="invisible" />

        <TextView
            android:id="@+id/badge_notification_1"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_alignParentEnd="true"
            android:layout_alignTop="@+id/userstatus4"
            android:layout_marginEnd="21dp"
            android:background="@drawable/circle_bg"
            android:gravity="center"
            android:padding="0sp"
            android:text="50"
            android:textColor="#fff"
            android:textSize="13sp"
            android:textStyle="bold"
            android:visibility="invisible" />

    </RelativeLayout>
</LinearLayout>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download