Sunday, August 9, 2015

How to create a horizontal layout RadioGroup in Android

activity_main.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    tools:context=".MainActivity"
    android:background="#e0ffc1"
    >
    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Which is your most favorite?"
        />
    <!--
        android:orientation
            Should the layout be a column or a row?
            Use "horizontal" for a row, "vertical" for a column.
    -->
    <RadioGroup
        android:id="@+id/rg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@id/tv"
        android:padding="15dp"
        >
        <RadioButton
            android:id="@+id/rb_coldfusion"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ColdFusion"
            android:paddingRight="10dp"
            />
        <RadioButton
            android:id="@+id/rb_flex"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Flex"
            android:paddingRight="10dp"
            />
        <RadioButton
            android:id="@+id/rb_flash"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Flash"
            android:paddingRight="10dp"
            />
    </RadioGroup>
</RelativeLayout>
More android examples