如何自定义内的微调TextView的? [英] How to customise the TextView inside a Spinner?

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

问题描述

我有与饲料值到它的一个ArrayAdapter一个微调。这个观点的布局看起来是这样的:

I have a Spinner with an ArrayAdapter that feeds Values into it. The layout for this views looks something like this:

        <TextView
           android:text="Household Income: "
           android:layout_width="wrap_content"
           android:layout_height="fill_parent"
           android:gravity="center_vertical" />

        <Spinner
           android:id="@+id/incomespinner"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:padding="2dip"  />

现在的问题是,该文本是长期的看法,结果是一个非常非常丑陋的微调。由于可以在截图中可以看出:

The Problem is that the text is to long for the view and the result is a very very ugly spinner. As can be seen in the screenshot:

我试图通过我自己的TextView将ID为适配器,但每次的微调应该显示我得到一个例外,我提供的id是无效的:

I tried to pass the Id of my own TextView into the Adapter but everytime the spinner should be shown I get an Exception that the Id I supplied is not valid:

04-26 17:38:39.695: ERROR/AndroidRuntime(4276): android.content.res.Resources$NotFoundException: Resource ID #0x7f09003a type #0x12 is not valid

我在哪里有定义的TextView?在一个单独的XML文件?与周围的ViewGroup?

Where do I have to define the TextView? In a separate xml file? With a surrounding viewgroup?

这将帮助我很多,如果我能看见的适配器初始化的一个例子,TextView的定义是什么?

It would help me a lot if I could see an example of the adapter initialization and the textview definition?

推荐答案

答案是从微调的定义中移除填充。 每次我设置了微调的填充文本得到了形。

The answer was to remove the padding from the definition of the Spinner. Every time I set the padding of the Spinner the Text gets out of shape.

微调器绘制使用填充盒从九个补丁程序,以确定在哪里画的内容。如果我设置了手动填充从填料箱填充的定义将被覆盖。

The spinner drawable is using the padding box from the nine patch to determine where to draw the the content. If I set a padding manually the definition of the padding from the padding box will be overridden.

如果您要设置除了填充中,您需要包装的一切,paddinbox内进入一个额外的布局容器中的填充。

If you want to set a padding in addition to a padding box you need to wrap everything inside that paddinbox into an additional Layout container.

这篇关于如何自定义内的微调TextView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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