我正在學習Android App Dev。我的問題是radioButtons在我的editText1和editText2上。我夢見順序如下:如何將RadioGroup移動到指定位置EditText Android Dev
- EDITTEXT與第一數
- EDITTEXT與第二數
- 單選按鈕+
- 單選按鈕 -
- 單選按鈕*
- 單選按鈕/
- textView結果
- BUTTON
其中第(i + 1)個元素低於第i個元素。
我想知道我該怎麼做,因爲當我將android:layout_below="@+id/editText2"
添加到radioGroup中時,它什麼也沒有。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.addme.calculator.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="first number"
android:layout_alignParentTop="true"
android:inputType="number" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:hint="second number"
android:inputType="number" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioGroup">
android:layout_below="@+id/editText2"
<RadioButton
android:id="@+id/radioPlus"
android:layout_below="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="+" />
<RadioButton
android:layout_below="@+id/radioPlus"
android:id="@+id/radioMinus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
<RadioButton
android:id="@+id/radioMult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_below="@+id/radioMinus"
android:text="*" />
<RadioButton
android:id="@+id/radioDiv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="/"
android:layout_below="@+id/radioMult"
android:layout_above="@+id/button" />
</RadioGroup>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:onClick="onButtonClick"
android:text="Button"
/>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/radioGroup"
android:text="Result" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
使用'android:layout_below' –