Share Coding

Tutorials, Problems, Stuffs …

Android Split line or one side border

When using add border to a view, the divider between two ListView  is not always display correctly. After the list item onDraw(), divider will overlapped by the list item.

So the better way is insert a view between two view and have only 1 or 2 dp width / heigh, using drawable/mydivder.xml or @color/XXX to change the color.

Create divider.xml in res/drawable folder

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

    <solid android:color="@color/divider"/>
    <size android:width="1dp"
          android:height="1dp" />

</shape>

@color/divider is a color defined in res/value/color.xml

 

In your layout/activity.xml

<LinearLayout
    android:id="@+id/topPanel"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"></LinearLayout>
<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@drawable/divider" />
<LinearLayout
    android:id="@+id/bottomPanel"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:baselineAligned="false"
    android:orientation="horizontal"></LinearLayout>

sample :
sample

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: