如何在Android中设计微调器

时间:2013-08-06 07:43:38

标签: android android-layout android-ui android-spinner

我想设计一个微调器,如下图所示:

Enter image description here

我没有在旋转器中指向下方的箭头符号。我怎么能这样做?

如果我制作如上所示的按钮设计,那么我必须编写额外的代码以获得与微调器类似的功能,因为Spinner没有android:drawableRight="@drawable/arraodown",但是在按钮中我们有这个方法。 / p>

3 个答案:

答案 0 :(得分:11)

不要乱用右/左/ ......抽屉。

只需将一个9-patch drawable设置为限制内部内容的背景。

<Spinner
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/you_spinner_drawable" />

关于9-patch drawable,请查看android资源或此示例图片来自this blog post(其中详细介绍了如何制作自定义微调器):

spinner drawables example

有关9-patch drawables的信息,请参阅android文档: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch http://developer.android.com/tools/help/draw9patch.html

当然,您也可以将状态列表xml文件指定为drawable,例如

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When disabled -->
    <item android:state_enabled="false"
        android:drawable="@drawable/your_disabled_spinner_drawable" />
    <!-- When selected -->
    <item android:state_pressed="true"
        android:drawable="@drawable/your_selected_spinner_drawable" />
    <!-- When not selected-->
    <item
        android:drawable="@drawable/your_default_spinner_drawable" />
</selector>

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

答案 1 :(得分:1)

您必须为微调器创建自定义布局。我认为以下XML可能会给你一个想法。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="3dip">

    <TextView
        android:id="@+id/number"
        android:padding="3dip"
        android:layout_marginTop="2dip"
        android:layout_marginLeft="5dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>

答案 2 :(得分:0)

只需使用GIMP作为图片编辑器,然后使用您喜欢的颜色更改背景颜色和边框。

例如,我通过编辑我在互联网上找到的现有图像来完成此图像:http://sdrv.ms/1lRkTbG