【发布时间】:2017-11-22 18:19:22
【问题描述】:
我正在学习 Android 应用开发。我的问题是radioButtons 在我的editText1 和editText2 上。我梦见了这个订单:
- editText 与第一个数字
- 用第二个数字编辑文本
- 单选按钮 +
- 单选按钮 -
- 单选按钮 *
- 单选按钮/
- 文本查看结果
- 按钮
第 (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
标签: android xml calculator android-relativelayout