Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinearLayout dividers are not showing [duplicate]

I am working on an android project and I have a LinearLayout which contains 2 horizontal buttons using borderless button style.

I am trying to show dividers in between each button but they are not showing up but I can't see any reason why not. Below is the XML layout:

<LinearLayout android:id="@+id/call_log_select_host_button_group"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:divider="#ffffff"
        android:showDividers="middle"
        android:dividerPadding="22dp">
        <Button android:id="@+id/call_log_select_btnCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Cancel"
            style="?android:attr/borderlessButtonStyle" />
        <Button android:id="@+id/call_log_select_btnBlock"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Block"
            style="?android:attr/borderlessButtonStyle" />
    </LinearLayout>

Thanks for any help you can provide.

like image 288
Boardy Avatar asked May 28 '13 22:05

Boardy


2 Answers

Create a file mydivider.xml inside res/drawable and put the following shape

<?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>

add the shape as divider for your layout

<LinearLayout android:id="@+id/call_log_select_host_button_group"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:divider="@drawable/mydivider"
        android:showDividers="middle"
        android:dividerPadding="22dp">
        <Button android:id="@+id/call_log_select_btnCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Cancel"
            style="?android:attr/borderlessButtonStyle" />
        <Button android:id="@+id/call_log_select_btnBlock"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Block"
            style="?android:attr/borderlessButtonStyle" />
    </LinearLayout>

or as workaround:

<LinearLayout android:id="@+id/call_log_select_host_button_group"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:divider="@drawable/mydivider"
        android:showDividers="middle"
        android:dividerPadding="22dp">
        <Button android:id="@+id/call_log_select_btnCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Cancel"
            style="?android:attr/borderlessButtonStyle" />

         <View    android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:background="#ffffff" />

        <Button android:id="@+id/call_log_select_btnBlock"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Block"
            style="?android:attr/borderlessButtonStyle" />
    </LinearLayout>
like image 80
Blackbelt Avatar answered Oct 14 '22 13:10

Blackbelt


Try replacing android:divider="#ffffff" with android:divider="@android:color/white". My suspicion is that divider has to be a Drawable, and hard-coding the color may not treat it like a Drawable, but referencing it might.

like image 10
Jason Robinson Avatar answered Oct 14 '22 15:10

Jason Robinson