我可以把Button放在Spinner中吗?

时间:2015-11-02 18:15:05

标签: java android

我可以在Spinner中使用String-array 但我不知道我能不能放其他东西? 我想把一些Button放在Spinner中但是当我把一些用于XML时,应用程序崩溃了!!

    <Spinner
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/spinner"
    android:layout_below="@+id/textView"
    android:layout_toRightOf="@+id/textView"
    android:layout_toEndOf="@+id/textView"
    android:layout_marginTop="125dp" >
    <Button
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />


</Spinner>

这是正确的方法吗? 或者是什么 ???

1 个答案:

答案 0 :(得分:0)

这不会起作用,因为这不是将按钮放在微调器中的方式。

按定义Spinner是一个几乎可以采用任何布局的下拉菜单。首先,你必须决定你的微调器行如何。

e.g:

如果你想要2个按钮,你需要制作一个layout / spinner_row.xml文件:

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

    <Button
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button" />

    <Button
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button2" />
</LinearLayout>

看起来像:

Result

然后你必须制作一个适配器,使用你想要的数据来调整微调器的每一行。