Android xml 参数化 View

标签 android android-layout parameterized

我一直在寻找一种在布局中声明参数化 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/

相关文章:

安卓 : Error Snack bar not showing correctly with Map View

java - 在运行时构建 Java 文件并在该类文件上运行 JUnit 测试

java.lang.NoSuchMethodException : [class android. app.Activity,int]

java - Jackson 反序列化 json Map - Map<String,Map<String,String>> 作为一个对象

android - LinearLayout 权重未填充父级

build - Teamcity - 参数化构建

hibernate - 在 Hibernate 中防止 SQL 注入(inject)

android - 如何取消闹钟?

android - 如何获取值不等于0的 child

android - ScrollView中的最小高度fill_parent和高度wrap_content? (或者只是电子邮件应用程序编写布局的代码)