1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Drain Droids

Android Studio For Beginners.Mobile Apps.Android Games.

Wednesday, January 9, 2019

How to Use Horizontal Divider in Android Studio



In this short tutorial, I am going to demonstrate how I use Horizontal Divider to make horizontal line.

Maybe you could also achieve this using some other method, but I am going to show you the method which I normally used.

Sometimes, you may want to use horizontal divider to demarcate or add some beauty to your UI design.

Let’s begin
While in your Text, add below code where you want the horizontal divider line.

<View android:id="@+id/view" android:layout_width="match_parent" android:layout_height="10dp" android:background="@android:color/holo_blue_bright" />

If you paste the code above code, you will get above horizontal Divider
Repeat the code as many as you want base on the numbers of dividers you want.
To change the color of the horizontal divider, erase the holo_blue_bright from the code and type the first letter of the color
you want e.g. red, blue etc. for example let say you want to change the horizontal divider color to Red , type R for red and it will bring a list of drop down colors to choose.
To change the height, change the number presented in db. From the image above the first horizontal
divider is 10db while the second divider is 3db.
You can always copy and paste the below code to see the result. Hope that was
helpful.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

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

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

            <Space
                android:layout_width="match_parent"
                android:layout_height="50dp" />

            <View
                android:id="@+id/view"
                android:layout_width="match_parent"
                android:layout_height="10dp"
                android:background="@android:color/holo_blue_bright" />

            <Space
                android:layout_width="match_parent"
                android:layout_height="50dp" />

            <View
                android:id="@+id/view3"
                android:layout_width="match_parent"
                android:layout_height="3dp"
                android:background="@android:color/holo_blue_bright" />

            <Space
                android:layout_width="match_parent"
                android:layout_height="50dp" />

            <View
                android:id="@+id/view4"
                android:layout_width="match_parent"
                android:layout_height="3dp"
                android:background="@android:color/holo_blue_bright" />


        </LinearLayout>
    </ScrollView>