根据屏幕的分辨率用代码来实现适配
例子:
用RadioButton来实现tab切换,布局文件中设置drawableTop属性引入图片,但是就会有一个问题,这样引入的图片好像不能修改大小,不能适配
解决办法,直接上代码
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics=new DisplayMetrics();
display.getMetrics(outMetrics);
densi=(int)(outMetrics.density);
changeSize(rb_home);
/**
* 改变drawableTop的大小
* @param rb_button
*/
private void changeSize(RadioButton rb_button) {
Drawable[] drawables = rb_button.getCompoundDrawables();
drawables[1].setBounds(0, 0, 25*densi, 25*densi);
rb_button.setCompoundDrawables(drawables[0],drawables[1],drawables[2],drawables[3]);
}
本文介绍了一种使用代码实现界面元素在不同屏幕分辨率下自动适配的方法。通过获取屏幕密度并调整RadioButton的drawableTop属性,确保图标能在各种分辨率的屏幕上正确显示。
4756

被折叠的 条评论
为什么被折叠?



