Divider for vertical LinearLayout?
Asked Answered
P

1

10

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?

Psycho answered 22/10, 2013 at 1:54 Comment(0)
M
26

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

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

with

  <size android:height="1dip" />
Misreckon answered 22/10, 2013 at 2:35 Comment(3)
Or rather, you need to have two drawables, one with the width set to 1dip, and one with the height set to 1dipMisreckon
You saved me from killing myself ;)Nival
Damn, that should have been obvious. Thanks for this.Echolalia

© 2022 - 2024 — McMap. All rights reserved.