Home » Android » Android layout equivalent of HTML HR tag?

Android layout equivalent of HTML HR tag?

Posted by: admin April 23, 2020 Leave a comment

Questions:

Is there any Android layout equivalent for HTML <HR /> tag?

How to&Answers:

You can use next trick:

<View 
   android:layout_width="match_parent"
   android:layout_height="2dp"       
   android:background="#ffffff"/>

This will draw horizontal line of white color with 2dp in height.

Answer:

Use View tag as:

<View 
android:layout_height="1dp" 
android:layout_width="match_parent" 
android:background="@#000000"/>

it will give you a line.

update: Using dp in layout_height and no px

Answer:

Thanks, just used your idea, but had to do it programatically, adding as a view like so:

    View horizontalRule = new View(getApplicationContext());
    horizontalRule.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
    ));
    horizontalRule.setMinimumHeight(2);
    horizontalRule.setBackgroundColor(Color.GREEN);
    ((LinearLayout)linearLayout).addView(horizontalRule);

Answer:

In html is horizontal line a tag hr. In Android source code you can use a View as xml example bellow.

< View
android:layout_width="fill_parent"
android:layout_height="4dip"
android:background="#ffffff"
android:paddingBottom="10dip"
/>

This works for you…

Answer:

In android no xml tag for that. The alternative for that is create a textview with layout height as 1 dip and background with black color. So that you will get 1 horizontal line