Create view separator horizontal line in android using xml

Draw divider horizontal line between two views to display them as separately on android application activity.

Separator line is used to separate two views inside android activity with the use of divider line it will make views individually so app user can easily understand both views. In this tutorial we are creating a View between two textview and separate them using Separator line. So here is the complete step by step tutorial for Create view separator horizontal line in android using xml.

android-project-download-code-button

How to Create view separator horizontal line in android using xml.

Code for MainActivity.java file.

 package com.viewseparatorline_android_examples.com;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.viewseparatorline_android_examples.com.MainActivity" >

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="182dp"
 android:text="TextView text 1"
 android:textAppearance="?android:attr/textAppearanceLarge" />

 <TextView
 android:id="@+id/textView2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/textView1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="38dp"
 android:text="TextView text 2"
 android:textAppearance="?android:attr/textAppearanceLarge" />

 <View
 android:id="@+id/view1"
 android:layout_width="fill_parent"
 android:layout_height="2dp"
 android:layout_alignParentRight="true"
 android:layout_below="@+id/textView1"
 android:layout_marginTop="20dp"
 android:background="#ff9703" />

</RelativeLayout>

Screenshot:

Create view separator horizontal line in android using xml

Click here to download Create view separator horizontal line in android using xml project.

Leave a Reply

Your email address will not be published. Required fields are marked *