Android Button无法在RelativeLayout中填满空间 [英] Android Button not filling full space in RelativeLayout

查看:181
本文介绍了Android Button无法在RelativeLayout中填满空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个与页面底部对齐的按钮.我希望它从左,右和底部填充100%的空间.无论我选择什么属性,仍然会有非常小的非覆盖区域.你能帮忙吗?

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>

此处是屏幕截图,显示了未填充的区域

推荐答案

您看到的空间是背景可绘制区域中按钮周围的阴影.您需要创建自己的背景可绘制对象,然后应完全占据其宽度.

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"

这篇关于Android Button无法在RelativeLayout中填满空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆