Azeem Khan Azeem Khan - 5 months ago 22
Android Question

How to make a RadioGroup scrollable in Android?

I have a simple layout wherein there is a TextView, followed by a RadioGroup followed by another TextView (and finally an Admob adview). I am trying to make the RadioGroup scrollable and for the life of me, I cannot seem to make it do that. Please advise. My xml code is attached.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"

>

<TextView
android:id="@+id/textview_statement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="@string/wait"
android:textSize="18sp"
/>

<ScrollView
android:id="@+id/scrollview_choices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_below="@id/textview_statement"
>

<RadioGroup
android:id="@+id/choices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"
>

<RadioButton
android:id="@+id/choice1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/choice" />

<RadioButton
android:id="@+id/choice2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choice" />

<RadioButton
android:id="@+id/choice3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choice" />

<RadioButton
android:id="@+id/choice4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choice" />

<RadioButton
android:id="@+id/dontknow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/choice"
android:checked="true" />

</RadioGroup>

</ScrollView>

<Button
android:id="@+id/actonchoice_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/adViewQ"
android:layout_marginBottom="2dp"
android:text="@string/actonchoice"
android:onClick="actOnChoice"
android:textSize="12sp"
/>

<com.google.ads.AdView
android:id="@id/adViewQ"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId=""
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
/>

</RelativeLayout>

Answer

The problem is that whenever the first textview (textview_statement) has a lot of text, one or more radio buttons in the radiogroup are hidden by the button (actonchoice_button). And if I try to scroll, nothing happens. The choices remain hidden by the button.

Add android:above="@+id/actonchoice_button" to your ScrollView, to say that you want it to have its bottom edge anchored to the top of your Button. Then, the ScrollView, and its RadioGroup, will not go under the Button.