【问题标题】:How to make a RadioGroup scrollable in Android?如何在 Android 中使 RadioGroup 可滚动?
【发布时间】:2013-05-12 15:40:36
【问题描述】:

我有一个简单的布局,其中有一个 TextView,然后是 RadioGroup,然后是另一个 TextView(最后是 Admob adview)。我正在尝试使 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 中,那么具体是什么问题?
  • 您好。问题是,每当第一个文本视图(textview_statement)有很多文本时,radiogroup 中的一个或多个单选按钮都会被按钮(actonchoice_button)隐藏。如果我尝试滚动,什么也不会发生。选项仍然被按钮隐藏。

标签: android android-scrollview android-radiogroup


【解决方案1】:

问题在于,每当第一个文本视图(textview_statement)有很多文本时,radiogroup 中的一个或多个单选按钮就会被按钮(actonchoice_button)隐藏。如果我尝试滚动,什么也不会发生。选项仍然被按钮隐藏。

android:layout_above="@+id/actonchoice_button" 添加到您的ScrollView,表示您希望它的底部边缘锚定到您的Button 的顶部。然后,ScrollView 及其RadioGroup 将不会归于Button

【讨论】:

  • CommonsWare,非常感谢。效果很好,我想我明白为什么了!
猜你喜欢
  • 2016-02-11
  • 2015-02-09
  • 1970-01-01
  • 1970-01-01
  • 2012-11-20
  • 1970-01-01
  • 2017-12-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多