Search code examples
androidbuttonandroid-relativelayout

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 very small non covered areas. Can you please help?

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    tools:context="com.example.myapplication.MainActivity">

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_margin="0dp"
        android:padding="0dp"
        android:text="search"

        />
</RelativeLayout>

Here is the screenshot, showing not filled areas


Solution

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