根据屏幕的分辨率用代码来实现适配
例子:
用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]);
}