如何在Android中使RadioGroup可滚动?

4

我有一个简单的布局,其中有一个TextView,接着是一个RadioGroup,然后是另一个TextView(最后是一个Admob广告视图)。我试图使RadioGroup可滚动,但我无论如何似乎都无法实现。请给予建议。我的xml代码附在下面。

<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>

既然您已经将RadioGroup包装在ScrollView中,那么具体问题是什么? - CommonsWare
你好。问题在于,每当第一个文本视图(textview_statement)有很多文本时,单选按钮组中的一个或多个单选按钮会被按钮(actonchoice_button)隐藏。如果我尝试滚动,什么也不会发生。选择仍然被按钮隐藏。 - Azeem Khan
1个回答

4
问题是,每当第一个文本视图(textview_statement)有大量文本时,单选按钮中的一个或多个会被按钮(actonchoice_button)隐藏。如果我尝试滚动,什么也不会发生。选择仍然被按钮隐藏。
为了解决这个问题,请在你的ScrollView中添加android:layout_above="@+id/actonchoice_button",表示你希望它的底部边缘锚定到你的Button的顶部。然后,ScrollView及其RadioGroup将不会进入Button下方。

CommonsWare,非常感谢。完美地工作了,我想我明白为什么了! - Azeem Khan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接