布局文件 :
<?xml version="1.0" encoding="utf-8"?> <DirectionalLayout xmlns:ohos="http://schemas.huawei.com/res/ohos" ohos:height="match_parent" ohos:width="match_parent" ohos:orientation="vertical"> <!-- 单选按钮容器 --> <RadioContainer ohos:id="$+id:radioContainer" ohos:height="match_content" ohos:width="match_parent" ohos:orientation="vertical"> <RadioButton ohos:id="$+id:radioButton1" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:text="单选按钮 0" ohos:text_size="100"/> <RadioButton ohos:id="$+id:radioButton2" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:text="单选按钮 1" ohos:text_size="100"/> <RadioButton ohos:id="$+id:radioButton3" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:text="单选按钮 2" ohos:text_size="100"/> </RadioContainer> <Text ohos:id="$+id:text" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:text="当前选中 : " ohos:text_size="100" ohos:text_color="#FF0000"/> </DirectionalLayout>
执行结果 :
三、GitHub 地址
GitHub 主应用 : https://github.com/han1202012/HarmonyHelloWorld
RadioButton 与 RadioContainer 组件示例 Module : https://github.com/han1202012/HarmonyHelloWorld/tree/master/radiobutton