Android Drawing Separator/Divider Line in Layout

Android Drawing Divider in Layout

In your styles xml, you could add this code for a vertical divider.

<style name="Divider">
<item name="android:layout_width">1dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:background">@android:color/darker_gray</item>
</style>

Then in your main activity xml, you could add

<View style="@style/Divider" />

between the two linear layouts, so the final code would be along the lines of

<Linear Layout... for Team A/>
<View style="@style/Divider" />
<Linear Layout... for Team B/>

Hope it helps.

How to Create or Drawing Separator/Divider Line with text in Layout android?

1.if you want to use constraint layout

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<View
android:id="@+id/first_divider"
android:layout_width="0dp"
android:layout_height="1dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/text"
android:background="@color/white80"/>

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="@+id/first_divider"
app:layout_constraintBottom_toBottomOf="@+id/first_divider"
app:layout_constraintStart_toEndOf="@+id/first_divider"
app:layout_constraintEnd_toStartOf="@+id/second_divider"
android:textColor="@color/white80"
android:text="OR"/>

<View
android:id="@+id/second_divider"
android:layout_width="0dp"
android:layout_height="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/text"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:background="@color/white80"/>

</androidx.constraintlayout.widget.ConstraintLayout>

2.if you want to use LinearLayout

 <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal">

<View
android:id="@+id/first_divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:background="@color/white80"/>

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white80"
android:text="OR"/>

<View
android:id="@+id/second_divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="@color/white80"/>

</LinearLayout>

3.if you want using relative layout

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal">

<View
android:id="@+id/first_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_toLeftOf="@+id/text"
android:layout_centerVertical="true"
android:background="@color/white80"/>

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="@color/white80"
android:text="OR"/>

<View
android:id="@+id/second_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/text"
android:background="@color/white80"/>

</RelativeLayout>

Here the result :

Sample Image

How to create simple divider/separator in home widget between views

Change View into LinearLayout.

<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/widget_title_id"
android:background="@android:color/darker_gray"/>

Create a custom divider in a layout

You can use a tiled xml bitmap.

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/back"
android:tileMode="repeat" />

Android draw a Horizontal line between views

It will draw Silver gray colored Line between TextView & ListView

<TextView
android:id="@+id/textView1"
style="@style/behindMenuItemLabel1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:text="FaceBook Feeds" />

<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#c0c0c0"/>

<ListView
android:id="@+id/list1"
android:layout_width="350dp"
android:layout_height="50dp" />

Android - divider between items in vertical layout

You can use a textview to create a divider line

Example:

<TextView          
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="#DADADA" />


Related Topics



Leave a reply



Submit