不知道怎么起標題,就這樣了。
目前主要講兩個方面內容:
- 代碼方式 設置RadioButton的 android:button 、 android:background 等屬性為 @null ;
- 代碼方式 通過布局模板動態創建固定參數的RadioButton等控件對象
1、代碼設置@null
// 這里不能用null,必需采用以下方式設置 radioButton.setButtonDrawable(getResources().getDrawable(android.R.color.transparent)); // 對於background則可以簡單使用null radioButton.setBackground(null);
2、通過布局模板創建控件對象
先創建包含所有默認參數的單個控件布局xml腳本模板,這里跟創建ListView使用的item布局腳本是差不多的東西
<?xml version="1.0" encoding="utf-8"?> <RadioButton xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="1" android:background="@null" android:button="@null" android:drawablePadding="-20dp" android:drawableTop="@drawable/cat" />
通過代碼引入上面的模板,創建新對象
RadioButton radioButton = (RadioButton) getLayoutInflater().inflate(R.layout.radiobutton, null);