Android切换按钮自定义大小/填充/间距 [英] Android Toggle Button custom size/padding/spacing

查看:164
本文介绍了Android切换按钮自定义大小/填充/间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的Android切换按钮创建自定义样式.更改颜色和文本没问题,但是我在更改大小/填充/间距或使其默认情况下显得如此不必要的大小方面遇到了麻烦. 我已经将height设置为wrap_content,padding和margin设置为0,但是按钮的大小仍然和默认的Toggle Button一样大.

I'm trying to create a custom style for my Android Toggle Buttons. Changing colour and text was no problem but I'm having trouble changing the size/padding/spacing or whatever it is that let them appear so unnecessarily large by default. I've set height to wrap_content and padding and margin to 0, but the size of the button is still as a big as the default Toggle Button.

你们中有人知道我必须更改哪些参数才能删除按钮的文本和边框之间不必要的间距吗?

Does anyone of you know what parameters I've to change to remove to unnecessary spacing between the button's text and border?

这是链接,指向我想要实现的图像. 从左到右:默认ToggleButton,我当前的ToggleButton和所需的ToggleButton种类.

Here's a link to an image of what I want to achive. From left to right: Default ToggleButton, my current ToggleButton and the kind of ToggleButton I want.

这是我的代码(当我动态添加这些按钮时,没有xml)

Here's my code (as I add those buttons dynamically, no xml)

ToggleButton button = new ToggleButton(getContext());
button.setLayoutParams(new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
button.setId(IDCreator.getID());
button.setText(tag);
button.setTextOff(tag);
button.setTextOn(tag);
button.setGravity(Gravity.LEFT);
button.setPadding(0, 0, 0, 0);
button.setBackground(getContext().getResources().getDrawable(R.drawable.toggle_selector));

感谢您的帮助.亲切的问候.

Thanks for your help. Kind regards.

图像和代码

推荐答案

我意识到这已经过时了,但是也许使用setScaleX({provide a float 0.0-1.0})和setScaleY({provide a float 0.0-1.0})是原始帖子的答案(如何更改切换按钮的大小).

I realize this is outdated, but perhaps using setScaleX({provide a float 0.0 - 1.0}) and setScaleY({provide a float 0.0 - 1.0}) might be the answer for the original post (how to change the size of the toggle button).

这篇关于Android切换按钮自定义大小/填充/间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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