背景尺寸变了 [英] Background size getting changed

查看:36
本文介绍了背景尺寸变了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以编程方式更改按钮的背景颜色,如下所示

I'm changing Background color of a button programmatically as below

     Button button =(Button)findViewById(R.id.one);
    button.setBackgroundColor(0xFFFF0000);

但是在此之后按钮的大小增加了.. 我在 UI 中使用了相对布局.

But after this the size of button getting increased.. Im using relative layout in UI.

推荐答案

默认按钮背景可绘制有某种边距.这些边距只是图像两侧的透明像素.当您为按钮设置背景颜色时,这些边距会消失,因为按钮的整个矩形都填充了颜色.

Default button background drawable has some kind of margins. These margins are just transparent pixels on the sides of the image. When you set background color for a button these margins disappear because the whole rectangle of the button is filled with the color.

这篇关于背景尺寸变了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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