Search code examples
androidwidgetandroid-widgetseparatordivider

How to create simple divider/separator in home widget between views


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"/>

Solution

  • 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"/>