平方X 发表于 2016-5-26 20:39:35

自定义内部类的View。 how does one reference a View that is an inner c...

看谷歌Creating a View Class时【/training/custom-views/create-view.html】
看到这样一段话,
Notice the name of the XML tag that adds the custom view to the layout. It is the fully qualified name of the custom view class. If your view class is an inner class, you must further qualify it with the name of the view's outer class. further. For instance, the PieChart class has an inner class called PieView. To use the custom attributes from this class, you would use the tag com.example.customviews.charting.PieChart$PieView.
感觉是比较生僻的知识点,于是试了一下。
结果Tag start is not closed.
查了一下。
http://stackoverflow.com/questions/2098318/error-referencing-an-inner-class-view-in-layout-main-xml
换成
<View
class="">
这个时候是不报错了,但是问题来了,我继承TextView,但是没有text啊。
而且,还有一点,不管我是用.还是$,不管内部耿达是不是static,都可以,继承Button也试了,但是就是没有Text。
还是在这里【http://stackoverflow.com/questions/2098318/error-referencing-an-inner-class-view-in-layout-main-xml】
Make sure the xml view tag is lower case then you should be able to cast it to the class you specified – wkarl Jul 16 '14 at 23:16
哈哈,成功。
整理一下。
①用<view class="{package}.{ParentClass}${innerClass}" />的形式
②public static InnerClass
③<View 应该是一个基类的View,class属性被忽略了,所以也不报错
④如果是PreferenceScreen还会有问题,见
【http://stackoverflow.com/questions/7249028/instantiating-an-inner-class-preference-in-xml-file】

平方X 发表于 2016-5-26 20:51:42

Notice that setShowText calls invalidate() and requestLayout(). These calls are crucial to ensure that the view behaves reliably. You have to invalidate the view after any change to its properties that might change its appearance, so that the system knows that it needs to be redrawn. Likewise, you need to request a new layout if a property changes that might affect the size or shape of the view. Forgetting these method calls can cause hard-to-find bugs.

平方X 发表于 2016-5-26 20:56:37

【android:contentDescription】
Design For Accessibility
Your custom view should support the widest range of users. This includes users with disabilities that prevent them from seeing or using a touchscreen. To support users with disabilities, you should:

Label your input fields using the android:contentDescription attribute
页: [1]
查看完整版本: 自定义内部类的View。 how does one reference a View that is an inner c...