Domanda

So I'm trying to put a divider between views in a LinearLayout using the XML android:divider attribute. When I use a vertical LinearLayout, no divider shows up. When I use a horizontal LinearLayout, the divider shows up and works fine. Here is the drawable I'm using for the divider (drawable/one.xml):

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <size android:width="1dip" />
    <solid android:color="#FFFFFF" />
</shape>

And here is my LinearLayout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:divider="@drawable/one"
              android:dividerPadding="10dp"
              android:showDividers="middle">
<TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="test1"
            />

<TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="test2"
            />

</LinearLayout>

Is it not possible to use the divider attribute with a vertical linear layout or am I missing something?

È stato utile?

Soluzione

For the vertical layout, in the drawable, I think you need to replace

  <size android:width="1dip" />

with

  <size android:height="1dip" />
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top