1

I've looking for a way to declare a parameterized view with in a layout. For example if I have a class NumericTextView<T> extends TextView I want to be able to declare it in an xml layout. The following doesn't seem like it will work because of the way the layout is parsed.

<NumbericTextView<Integer>/>

But could I potentially have something like this?

<NumbericTextView type:Integer/>

If that still won't work is there anything wrong with using some custom FrameLayout that switches on a parameter to add the correct NumbericTextView<T> child?

4

1 回答 1

1

您需要执行以下操作:

<com.my.ui.NumericTextView
    android:id="@+id/MyTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

看到android自定义文本视图不能添加到布局文件中

这用于自定义属性: http: //prasanta-paul.blogspot.com/2010/05/android-custom-textview.html

于 2013-02-06T18:11:03.267 回答