1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > android radiobutton 文字按钮的距离 android RadioButton 图片与文字间距问题

android radiobutton 文字按钮的距离 android RadioButton 图片与文字间距问题

时间:2023-02-14 13:35:51

相关推荐

android radiobutton 文字按钮的距离 android RadioButton 图片与文字间距问题

在使用radiobutton的按钮跟文字之间的间距在不同的手机上会出现间距不一致,今天学习到了如何解决这个问题:

android:button=@null;//将默认的button图片清空

android:drawableLeft=@drawable/radiobutton;//使用该属性定义button图片

android:background=@null;//将radioButton的背景设为空

android:drawablePadding=6dp;//将文字和左侧的button图片相距6dp

button/drawableLeft/background/drawablePadding结合使用方可改变文字和图片的距离 ;

一、xml文件

定义radio的样式、属性:

center_vertical

@null

0dp

@null

@drawable/package_radio_selector

10dp

package_radio_selector.xml的样式:

radioButton的使用:

style="@style/package_radio_style"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="测试"

android:textColor="@color/white"

android:textSize="15sp" />

样式的效果:

二、java方法

使用java创建的radioButton 解决图片与文字间距问题:

RadioButton radioButton2 = new RadioButton(this);

radioButton2.setText("测试");

radioButton2.setTextColor(getResources().getColor(R.color.white));

radioButton2.setTextSize(PLEX_UNIT_SP, 15);

radioButton2.setPadding(0, 0, 0, 0);

//radioButton2.setButtonDrawable(null); java设置ButtonDrawable为null,还是会显示原生的radio图标。设置为透明就好了。

radioButton2.setButtonDrawable(getResources().getDrawable(android.R.color.transparent));

radioButton2.setBackgroundDrawable(null);

radioButton2.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.package_radio_selector), null, null, null);

radioButton2.setCompoundDrawablePadding(10);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。