標籤:android
總結項目開發中的經驗,減少類似情況發生,提高開發效率:
樣本:
一、布局檔案中為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);
如有更好的解決方案,歡迎留言噢~
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
Android 開發知識點總結