1

I'm a student in an android development program. I've built a few apps and I had an idea to use a very simple TextView to draw a line across the screen to visually separate a page element. The TextView would hold no text, it has no function or use other than to separate two elements with a horizontal rule. I'm using it in a ConstraintLayout.

Can anyone give me a reason as to why this is NOT a good idea? What would the best practices be otherwise? Is it normal to use an empty TextView in this manner?

enter image description here

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Krausladen
  • 138
  • 10
  • Naaa, use a Frame layout and width match parent, height what you need and set the background color or drawable you want –  Sep 12 '20 at 00:39

1 Answers1

3

It's perfectly fine to do that, but it's unnecessary to use a TextView specifically: A TextView with no text is just a View.

You can just create a View with whatever height and background color and use that:

<View
    android:layout_width="match_parent"
    android:layout_width="1dp"
    android:background="@color/my_divider_color" />

Replace 1dp with whatever height you want and @color/my_divider_color with whatever color you want the divider to be.

Ryan M
  • 18,333
  • 31
  • 67
  • 74