-6

I want to add divider (a smooth transparent line between two views either horizontally or vertically )how can i achieve this here is my sample code.i need to add horizontal line between username and password(horizontally) and also between user icon and username hint(vertically)

<LinearLayout
            android:gravity="top"
            android:divider="?android:dividerHorizontal"
            android:layout_width="300dp"
            android:layout_marginLeft="20dp"
            android:layout_height="wrap_content"
            android:id="@+id/liner"
            android:orientation="vertical">
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/user"
                android:id="@+id/username"
                android:textColor="#bbc"
                />
            <EditText
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:hint="@string/usr_name"
                android:textColorHint="#bbc"
                android:backgroundTint="@android:color/transparent"
                android:textColor="@android:color/white"/>
        </LinearLayout>
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/paswd"
                android:id="@+id/password"
                android:textColor="#bbc"
                />
            <EditText
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:hint="@string/passwd"
                android:textColorHint="#bbc"
                android:backgroundTint="@android:color/transparent"
                android:textColor="@android:color/white"/>
        </LinearLayout>
    </LinearLayout>
AskNilesh
  • 58,437
  • 15
  • 99
  • 129
Balaraju M
  • 273
  • 2
  • 12

6 Answers6

3

for horizontal Line

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="username"
            android:id="@+id/username"
            android:textColor="#bbc"
            />
        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="#ebebeb"
            android:layout_margin="@dimen/margin_5"/>
        <EditText
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:hint="usr_name"
            android:textColorHint="#bbc"
            android:backgroundTint="@android:color/transparent"
            android:textColor="@android:color/white"/>
    </LinearLayout>

for vertical line

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="#cd2121"
        android:layout_margin="@dimen/margin_5"/>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/text_10">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="password"
            android:id="@+id/password"
            android:textColor="#bbc"
            />
        <View
            android:layout_width="0.5dp"
            android:layout_height="match_parent"
            android:background="your color"
            android:layout_margin="@dimen/margin_5"/>
        <EditText
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:hint="password"
            android:textColorHint="#bbc"
            android:backgroundTint="@android:color/transparent"
            android:textColor="@android:color/white"/>
    </LinearLayout>
Geeta Gupta
  • 1,222
  • 9
  • 16
2

Make a drawable file of below code, for divider line, and use it wherever you need, also change color according to your choice.

<View xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="0.7dp"
    android:background="#ebebeb" />
Stuti Kasliwal
  • 559
  • 6
  • 14
1

Between the two linear layout for username and password use the following:

<View
        android:id="@+id/line"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/black"/>
1

try below code

<View xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#cd2121" />
Shankar
  • 86
  • 6
0

Simply create another view in between userName & passowrd

<View 
android:layout_width="match_parent" 
android:layout_height="2dp"
 android:color="@color/divider_color"
 android:id="@+id/divider" />
surya
  • 549
  • 4
  • 16
0

You can add a divider by using the View tag with a height (or width if it's vertical) of 1dp between the views you want to divide:

<View
 android:id="@+id/line"
 android:layout_width="match_parent"
 android:layout_height="1dp"
 android:background="@color/yourColor/>
P Fuster
  • 1,901
  • 16
  • 27