如题:
我在xml文件里面
<RadioGroup
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="57dp"
android:orientation="horizontal"
android:background="#fcfcfc"
>
<RadioButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:text="hehe"
android:textColor="#000"
/>
<RadioButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:button="@null"
android:text="haha"
android:textColor="#000"
/>
</RadioGroup>
这样写,权重值有起作用
但是如果是动态添加
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/radioButton"
>
<style name="radioButton">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
<item name="android:button">@null</item>
</style>
RadioGroup group = (RadioGroup) findViewById(R.id.bottom);
String[] titles = {"测试1","测试2","测试3"};
int size = titles.length;
if(titles != null){
for(int i = 0; i< size; i++){
RadioButton radioButton = (RadioButton) LayoutInflater.from(this).inflate(R.layout.tabmenu_radiobutton,null);
radioButton.setId(i);
radioButton.setText(titles[i]);
group.addView(radioButton);
}
}
就变成
我想动态添加的radiobutton,能等比分配空,请问有大神能帮忙解决吗?