1
我想要得到佈局如下:組合框和編輯文本里面的radiogroup
| --r-- | --- c --- |
| --r-- | --- t --- |
「r」位置的小部件是單選按鈕,「c」是組合框,「t」是edittext。
我希望:
當第一個「r」被選中時,「c」被啓用並且「t」被禁用; 當選擇第二個「r」時,「c」被禁用並且「t」被啓用;
這可能嗎?怎麼樣?
我想要得到佈局如下:組合框和編輯文本里面的radiogroup
| --r-- | --- c --- |
| --r-- | --- t --- |
「r」位置的小部件是單選按鈕,「c」是組合框,「t」是edittext。
我希望:
當第一個「r」被選中時,「c」被啓用並且「t」被禁用; 當選擇第二個「r」時,「c」被禁用並且「t」被啓用;
這可能嗎?怎麼樣?
<TableLayout
<Table row>
<LinearLayout orientation:horizontal
<Radiogroup .....
android:orientation="horizontal"
/>
<Spinner ...
/>
</LinearLayout>
</TableRow>
<TableRow >
<LinearLayout orientation:horizontal
<Radiogroup .....
android:orientation="horizontal"
/>
<EditText ..... />
</LinearLayout>
</TableRow>
</TableLayout>
試試這個:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="10" >
<RadioGroup
android:id="@+id/radioSex"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="5" >
<RadioButton
android:id="@+id/radioMale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/radio_male" />
<RadioButton
android:id="@+id/radioFemale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/radio_female" />
</RadioGroup>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:orientation="vertical" >
<Spinner
android:id="@+id/cmbName"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/etName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</LinearLayout>
</LinearLayout>
代碼:
RadioGroup rgp = (RadioGroup) findViewById(R.id.radioSex);
final Spinner cmbName = (Spinner) findViewById(R.id.cmbName);
final EditText etName = (EditText) findViewById(R.id.etName);
rgp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.radioMale) {
etName.setEnabled(false);
cmbName.setEnabled(true);
} else {
etName.setEnabled(true);
cmbName.setEnabled(false);
}
}
});
使用tablelayout和tablerows添加小工具日子會把你得到你想要的佈局。 – Shruti
你的意思是兩個「r」小部件位於佔據兩行一列的同一個表元素中? – realjin
@Shruti但我怎麼能跨越行?我看到的教程展示瞭如何跨越列,但都不是跨越行! – realjin