根據屏幕的分辨率用代碼來實現適配
例子:
用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]);
}