Android的 - 问题与自定义背景微调 [英] Android - Issue with custom Spinner background

查看:229
本文介绍了Android的 - 问题与自定义背景微调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给一个自定义背景,以我的微调。我已经与9补丁格式下载了HTC Sense的设计微调(参看下面的图片)。


我已经创建了以下code里面的一个新的XML文件:

 <?XML版本=1.0编码=UTF-8&GT?;    <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>         <项目
             机器人:state_focused =真
             机器人:STATE_ pressed =假
             机器人:可绘制=@绘制/ spinner_ pressed/>        <项目
            机器人:state_focused =真
            机器人:STATE_ pressed =真
            机器人:可绘制=@绘制/ spinner_ pressed/>        <项目
            机器人:state_focused =假
            机器人:STATE_ pressed =真
            机器人:可绘制=@绘制/ spinner_ pressed/>        <项目
            机器人:可绘制=@绘制/ spinner_normal/>    < /选择>

和我添加了一个微调,以我的布局与此code:

 <微调
    机器人:ID =@ + ID / my_spinner
    机器人:layout_width =180dp
    机器人:layout_height =50dp
    机器人:layout_marginLeft =20dp
    机器人:背景=@绘制/ custom_spinner/>

但是,尽管被正确显示,我得到了以下格式:

我都做什么了吗?

我希望你能帮助我。

问候。


解决方案

在你的9补丁定义伸缩性领域似乎是错误的,这就是为什么你的9补丁被拉伸这样。看看九宫文档和注意到左边界定义了区域应拉伸。我想你也应该定义下面的箭头可伸缩的区域,如果你想要的箭头为中心。

如果你不知道如何编辑9补丁,你应该使用 draw9patch 它被包含在 AndroidSDK /工具

I'm trying to give a custom background to my spinner. I've downloaded the HTC sense spinner design (Cf. following pictures) with the 9 patch format.

I've created a new XML file with the following code inside:

    <?xml version="1.0" encoding="utf-8"?>

    <selector xmlns:android="http://schemas.android.com/apk/res/android">

         <item
             android:state_focused="true" 
             android:state_pressed="false" 
             android:drawable="@drawable/spinner_pressed" />

        <item
            android:state_focused="true" 
            android:state_pressed="true"
            android:drawable="@drawable/spinner_pressed" />

        <item
            android:state_focused="false" 
            android:state_pressed="true"
            android:drawable="@drawable/spinner_pressed" />

        <item
            android:drawable="@drawable/spinner_normal" />

    </selector>

And I've added a spinner to my layout with this code:

<Spinner
    android:id="@+id/my_spinner"
    android:layout_width="180dp"
    android:layout_height="50dp"
    android:layout_marginLeft="20dp"
    android:background="@drawable/custom_spinner" />

But whereas being correctly displayed, I got the following format:

Did I make something wrong?

I hope you'll can help me.

Regards.

V.

解决方案

The stretchable areas defined on your 9-patch seem wrong, and that is why your 9-patch are stretched like this. Have a look at Nine-patch docs and notice that the left-border defines what area should be stretched. I think you should also define a stretchable area below the "arrow" if you want the "arrow" to be centered.

If you do not know how to edit 9-patch you should use draw9patch it is included in the AndroidSDK/tools.

这篇关于Android的 - 问题与自定义背景微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆