排列单选按钮下方的文本,并完美地中心,为所有Android设备 [英] Arranging radio buttons just below the text and perfectly in center for all android devices

查看:255
本文介绍了排列单选按钮下方的文本,并完美地中心,为所有Android设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想安排只是文本低于无线电butons但我不能够做到这一点。我用的android:layout_marginLeft =20dp,但它适用于只有特定的设备并不适用于所有

I want to Arrange radio butons just below the text but I am not able to do it. I have used android:layout_marginLeft="20dp" but it works for only particular device not for all.

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/txt1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#ff0000"
        android:gravity="center"
        android:text="red" />

    <TextView
        android:id="@+id/txt2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#00ff00"
        android:gravity="center"
        android:text="green" />

    <TextView
        android:id="@+id/txt3"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="#0000ff"
        android:gravity="center"
        android:text="blue" />
</LinearLayout>

<RadioGroup
    android:id="@+id/rg_rgrp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="3" >

    <RadioButton
        android:id="@+id/rbtn_red"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:gravity="center" />

    <RadioButton
        android:id="@+id/rbtn_green"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center" />

    <RadioButton
        android:id="@+id/rbtn_blue"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center" />
</RadioGroup>

我用重力和layout_gravity但两者是可以正常使用的文字不是单选按钮。

I have used Gravity and layout_gravity both but it works properly for text not for radio buttons.

推荐答案

RadioGroup中应该是这样的。无需code。

Your RadioGroup should look like this. No code required.

<RadioGroup
    android:id="@+id/rg_rgrp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />
    <RadioButton
        android:id="@+id/rbtn_red"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />
    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="2" />
    <RadioButton
        android:id="@+id/rbtn_green"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />
    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="2" />
    <RadioButton
        android:id="@+id/rbtn_blue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />
    <View
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1" />
</RadioGroup>

这篇关于排列单选按钮下方的文本,并完美地中心,为所有Android设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆