【问题标题】:How to put a Spinner beside a RadioButton如何在 RadioButton 旁边放置 Spinner
【发布时间】:2013-05-15 16:22:47
【问题描述】:

我有这个布局:

(由于我的声誉还不到 10,我诚恳地请您查看此图片链接) http://tinypic.com/r/2q9f80z/5

我想在最后一个 RadioButton 旁边放一个 Spinner,如图所示。

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

<!-- Linearlayout containing the Search/Find Customer -->


    <!-- TextView for Search/Find Customer -->

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Search/Find Customer" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/etSearch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@layout/roundable_edittext"
        android:hint="@string/hint_search" >
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Search" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Cancel" />
</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp" >

    <TextView
        android:id="@+id/Options"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Search/Find Customer" />
</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/rdAllCustomers"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="All Customers" />

            <RadioButton
                android:id="@+id/rdToday"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Today" />

            <RadioButton
                android:id="@+id/rdToday"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Owner\&apos;s Name" />

            <RadioButton
                android:id="@+id/rdToday"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Trade Name" />

            <RadioButton
                android:id="@+id/rdToday"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Itinerary" />
        </RadioGroup>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <Spinner
            android:layout_width="163dp"
            android:layout_height="wrap_content"
            android:entries="@array/spinner_itinerary"
            android:gravity="bottom" />
    </LinearLayout>

</LinearLayout>

提前致谢!

【问题讨论】:

    标签: android android-layout radio-button spinner radio-group


    【解决方案1】:

    伙计,您不应该在单选按钮旁边使用微调器,这不是一个好的设计实践,而是应该将微调器放在单选按钮下方,如果用户选择单选按钮,您就可以让微调器可见。

    【讨论】:

    • 这是 Android 中的协议吗?我的项目是从Windows Phone(iPAQ)模仿一个.Net程序,它的外观是微调器在单选按钮旁边。
    • 它不是一个协议,它只是一个更好的实践设计。你的思维方式看起来有点杂乱无章,你知道吗?
    • 我说这是我项目的要求,而不是我想的那样。你也拼错了“杂乱无章”这个词。无论如何感谢您的启发,我会告诉我的团队负责人。
    【解决方案2】:

    我同意@Witalo。 Android 设计指南强烈建议不要模仿非 Android 移动操作系统(iOS、Windows Phone 等)的设计。但是,如果您的客户/客户需要它,您有以下我能想到的选项,

    • 子类RadioButton 改为绘制Spinner
    • 或者,使用RelativeLayout

    【讨论】:

    • 感谢您的替代方案,我很感激。我可以同时使用单选按钮旁边的微调器和单选按钮下方的微调器,这样我就可以将它呈现给我的团队负责人。我还发现完全模仿非安卓程序的外观很愚蠢,因为它们的行为非常不同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-22
    相关资源
    最近更新 更多