-2

I want to put a horizontal line within a textview in android studio. I want to create a textview layout like this.

K.Os
  • 5,123
  • 8
  • 40
  • 95
Lace Toledo
  • 7
  • 1
  • 1

4 Answers4

1

You can use this code to get TextView with a line .

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/tv_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Device"
        android:layout_centerVertical="true"
        android:layout_margin="3dp"
        />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#000"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/tv_textview"
        android:layout_margin="3dp"
        />

</RelativeLayout>
KeLiuyue
  • 8,149
  • 4
  • 25
  • 42
Arshad
  • 1,262
  • 16
  • 25
1
  • create linear layout with match_parent width
  • set orientation vertical
  • put text view child with wrap_content width
  • put view with 0dp width and weight = 1

    <View 
        android:layout_width="fill_parent"
        android:layout_height="1dp"       
        android:background="#000"
        android:gravity="bottom" />
    
KeLiuyue
  • 8,149
  • 4
  • 25
  • 42
Mostafa Anter
  • 3,445
  • 24
  • 26
0

Do it Programitically Like..

(Use _ for Making a Line)

yourTextView.setText("Device_________________________");
yourTextView.setTextColor("Your Color Here");

and In XML file Set

Android:width = "MatchParent".

for your Text View.

Do this only if you are creating static layout.

Learning Always
  • 1,563
  • 4
  • 29
  • 49
0

Draw custom drawable and set to drawableEnd to textview Drawable can something like this.. and do not forgot to set textview width match parent

vaibhav
  • 312
  • 2
  • 10