2

In my app I'm creating home widget, but i have problems to find how to create simple horizontal divider/separator between 2 TextViews.

This is a home widget layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/widget_RL_id"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#09C"
    android:padding="@dimen/widget_margin">

    <TextView
        android:id="@+id/widget_title_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:contentDescription="@string/appwidget_text"
        android:text="@string/appwidget_text"
        android:textSize="20sp"
        android:textStyle="bold|italic"
        android:layout_marginStart="5dp"
        android:layout_marginEnd="5dp"/>

    <TextView
        android:id="@+id/widget_datum_id"
        android:layout_alignParentEnd="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Datum"
        android:textStyle="bold|italic"
        android:textSize="8sp"
        android:layout_margin="8dp"
        />

    <TextView
        android:id="@+id/widget_theRest_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/widget_title_id"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="8dp"
        android:contentDescription="@string/appwidget_text"
        android:text="@string/appwidget_text"
        android:textColor="#ffffff"
        android:textSize="20sp"
        android:textStyle="bold|italic"
        android:layout_marginStart="5dp"
        android:layout_marginEnd="5dp"/>


</RelativeLayout>

I want to put separator/divider between 2 TextViews where first view is with id: widget_title_id, and second view is with id: widget_theRest_id.

I try to add divider this way, but android home widget do not support View, so its not working or maybe im doing something wrong:

<View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@id/widget_title_id"
        android:background="@android:color/darker_gray"/>
Cœur
  • 37,241
  • 25
  • 195
  • 267
NoName
  • 273
  • 7
  • 21
  • Possible duplicate of [Android Drawing Separator/Divider Line in Layout?](https://stackoverflow.com/questions/5049852/android-drawing-separator-divider-line-in-layout) – Micer Jul 19 '17 at 11:39
  • What does your **Run code snippet** button do? – IgorGanapolsky Aug 22 '17 at 14:12

3 Answers3

7

Change View into LinearLayout.

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@id/widget_title_id"
        android:background="@android:color/darker_gray"/>
aslamhossin
  • 1,217
  • 12
  • 22
1

To create a horizontal line/ divider between your textviews, just add this between them:

 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="2dp"
    android:background="your_color"/>

This will add a line between your textviews.

artenson.art98
  • 1,543
  • 15
  • 15
  • 2
    thank you for answering but i accept Aslam Hossin answer because he answer first. However, im giving you a plus – NoName Feb 19 '17 at 11:47
1

I believe that from performance point of view it's better to use only View component. There's no reason to use anything more complicated as there's no advantage with that.

<View
    android:id="@+id/divider"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@android:color/darker_gray" />
Micer
  • 8,731
  • 3
  • 79
  • 73