Skip to content Skip to sidebar Skip to footer

Android Button Not Filling Full Space In Relativelayout

I am trying to create a button, aligned to the bottom of the page. I want it to fill 100% space, from left, right and bottom. Whatever attributes I will choose, there are still ver

Solution 1:

Create a file in drawable folder like this, say simple_selector.xml

<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_pressed="false"><shapeandroid:shape="rectangle"><!-- Normal color --><solidandroid:color="@android:color/white" /></shape></item><itemandroid:state_pressed="true"><shapeandroid:shape="rectangle"><!-- Color - when the view is pressed --><solidandroid:color="@android:color/black"/></shape></item></selector>

Now simply set the background as the above created drawable.

<Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/simple_selector"
        android:text="search"

        />

The above code can change color in both normal and pressed states of the button. You can change the colors as per your requirement.

Solution 2:

The space you see is the shadow around the button in its background drawable. You need to create your own background drawable and it should then completely occupy the width.

Or, you could also just set the background to null.

android:background="@null"

Post a Comment for "Android Button Not Filling Full Space In Relativelayout"