对于自定义视图(振动的TextView)配置属性 [英] (Vibrating TextView) Configure attributes for custom views

查看:105
本文介绍了对于自定义视图(振动的TextView)配置属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚创建的类<​​code> VibratingTextView 。我打算创建小部件的全库,所以我想这样做的正确的方式。

I just created class VibratingTextView. I intend to create a whole library of widgets so I want to do it the right way.

在XML对于这样的观点:

The xml for this View:

<sherif.android.textview.VibratingTextView  
    android:id="@+id/textView2"  
    android:layout_width="wrap_content"  
    android:textAppearance="?android:attr/textAppearanceLarge"  
    android:layout_height="wrap_content"  
    android:orientation="horizontal"  
    android:text="outToRight" >  
</sherif.android.textview.VibratingTextView> 

请注意,它有安卓方向安卓文本。它接受一个的TextView 的属性和一个的LinearLayout 。类本身扩展的LinearLayout

Notice it has android:orientation and android:text. It accepts the attributes of a TextView and of a LinearLayout. The class itself extends LinearLayout.

我的问题是在Eclipse的XML编辑器。当用户键入 Android的:,Eclipse的智能感知为用户提供了可供选择的方案在这个命名空间

My problem is in the xml editor of eclipse. When the user types android:, eclipse's intellisense gives the user the options available in this namespace.

在我而言,这是给了的LinearLayout 等等,例如,文本和<$ C的属性$ C> TEXTSIZE 不会出现。

In my case, it is giving the attributes of LinearLayout so, for example, Text and TextSize do not appear.

有没有一种方法,使他们出现(使用机器人命名空间)?

Is there a way to make them appear (using the android namespace)?

如果没有,应该创建自己的命名空间,我定义的属性?或者是有没有办法导入Android的特性,使它们在谢里夫的属性?

If not, should I create my own namespace with attributes that I define? or is there a way to import the android's attributes and make them in sherif's attributes?

请记住,我创建使用通过了我的属性类的构造一个TextView。它工作正常,所有的TextView的属性被设置正确。

Keep in mind that I am creating a TextView in the constructor of my class using the attributes passed. It is working fine and all the attributes for the TextView are being set correctly.

由于我会创造出很多其他的部件,我可能需要我自己的命名空间,但什么是最好的做法是什么?例如,我要创建 alwaysVibrate 属性。这将是像谢里夫:alwaysVibrate =真正的。我想我的图书馆是可包含的和eclipse显示我的命名空间的属性:?我用用通常的方法 attr.xml

Since I will create many other widgets, I might need my own namespace but what is the best practice? For example, I want to create alwaysVibrate attribute. It will be something like sherif:alwaysVibrate="true". I want my library to be includable and eclipse to show the attributes of my namespace: I use the usual way using attr.xml?

推荐答案

我最近面临的相同问题。以下是 attrs.xml

I recently faced the exact same problem. Here are my custom attribute declarations in attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="NumberPicker">
        <attr name="rangeStart" format="integer|reference" />
        <attr name="rangeEnd" format="integer|reference" />
        <attr name="speed" format="integer|reference" />
        <attr name="current" format="integer|reference" />
        <attr name="android:orientation" />
    </declare-styleable>
</resources>

您可以重复使用Android的属性,但是你不能教他们建议不同的值。事实上,你甚至不能教日食表明你的自定义属性的定义(在后的这一天,至少,我希望在将来能看到该功能)。

You can reuse the android attributes but you can't teach them to suggest different values. In fact you can't even teach eclipse to suggest your custom attribute definitions (at least at this date of post, I would love to see that feature in future).

一切你想知道如何定义自定义属性是这样的问题: <一href="http://stackoverflow.com/questions/2695646/declaring-a-custom-android-ui-element-using-xml/2695649#2695649">Declaring一个定制的Andr​​oid UI元素使用XML 。

Everything else you would want to know about defining custom attributes is in the question: Declaring a custom android UI element using XML.

这篇关于对于自定义视图(振动的TextView)配置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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