总结项目开发中的经验,减少类似情况发生,提高开发效率:
示例:
一、布局文件中为TextView设置textColor及background颜色时区别:
background对应selector:
textColor对应的selector:
辨别差异O(∩_∩)O~,避免浪费不必要的开发时间~~
二、RadioGroup+Fragment写底部导航时,RadioGroup中的RadioButton中无法修改drawableTop图片的大小:
如图我觉得边上四个图标的大小不合适,但是又无法改变其大小。
如下setBounds方法可以大致解决该问题,不过可能不是最好的解决方法。
DisplayMetrics dm = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(dm); int width = dm.widthPixels; int height = dm.heightPixels; if (width <= 854 && height <= 480) { size = 20; } else if (width <= 1280 && height <= 720) { size = 55; } else { size = 70; } radioBtn1 = (RadioButton) radioGroup.getChildAt(0); image1 = this.getResources().getDrawable( R.drawable.btn_selector_compete); image1.setBounds(0, 0, size, size); radioBtn1.setCompoundDrawables(null, image1, null, null); radioBtn2 = (RadioButton) radioGroup.getChildAt(1); image2 = this.getResources().getDrawable( R.drawable.btn_selector_message); image2.setBounds(0, 0, size, size); radioBtn2.setCompoundDrawables(null, image2, null, null); radioBtn3 = (RadioButton) radioGroup.getChildAt(2); image3 = this.getResources().getDrawable( R.drawable.btn_selector_home_unpressed); image3.setBounds(0, 0, size, size); radioBtn3.setCompoundDrawables(null, image3, null, null); radioBtn4 = (RadioButton) radioGroup.getChildAt(3); image4 = this.getResources().getDrawable( R.drawable.btn_selector_discovery); image4.setBounds(0, 0, size, size); radioBtn4.setCompoundDrawables(null, image4, null, null); radioBtn5 = (RadioButton) radioGroup.getChildAt(4); image5 = this.getResources() .getDrawable(R.drawable.btn_selector_myself); image5.setBounds(0, 0, size, size); radioBtn5.setCompoundDrawables(null, image5, null, null);
如有更好的解决方案,欢迎留言噢~
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-12 04:09:57