我一直在寻找一种在布局中声明参数化 View 的方法。例如,如果我有一个类 NumericTextView<T> extends TextView
我希望能够在 xml 布局中声明它。由于布局的解析方式,以下内容似乎无法正常工作。
<NumbericTextView<Integer>/>
但是我可能有这样的东西吗?
<NumbericTextView type:Integer/>
如果还是不行,是不是使用一些自定义的有什么问题 FrameLayout
打开参数以添加正确的 NumbericTextView<T>
child ?
最佳答案
你会想做这样的事情:
<com.my.ui.NumericTextView
android:id="@+id/MyTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
参见 android custom text view can not be added in layout file
这是自定义属性:http://prasanta-paul.blogspot.com/2010/05/android-custom-textview.html
关于Android xml 参数化 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14735844/