在Android中使用相对布局上的单选按钮

时间:2012-11-27 15:45:46

标签: android list layout button

我目前有一个相对布局的Android项目。

我想让用户设置一个选项(在很长的列表中)。 环顾四周后,我注意到使用单选按钮并在对话框中显示它们的可能性,如here所述。 但我在API上看到,需要在线性布局中使用单选按钮。

是否有另一种让用户从列表中选择内容的方法?比如一种选择清单?

感谢您的帮助。我添加了当前的布局以便澄清。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFCC" >

    <Button
        android:id="@+id/buttonExit"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="Exit" />

    <Button
        android:id="@+id/buttonStart"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="52dp"
        android:text="Play" />

    <Button
        android:id="@+id/buttonStop"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/buttonStart"
        android:layout_marginTop="21dp"
        android:text="Pause" />

    <Button
        android:id="@+id/Continue"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/buttonStop"
        android:layout_marginTop="16dp"
        android:text="Continue" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Continue"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="36dp"
        android:text="Ready."
        tools:context=".MainActivity" />


</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

您可以使用Spinner或ListView。

您可以在此处找到信息和示例: http://developer.android.com/guide/topics/ui/controls/spinner.html