平方X

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 4290|回复: 2

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

[复制链接]

414

主题

709

帖子

3657

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3657
QQ
发表于 2016-5-26 20:39:35 | 显示全部楼层 |阅读模式
看谷歌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/questio ... -in-layout-main-xml
换成
<View
class="">
这个时候是不报错了,但是问题来了,我继承TextView,但是没有text啊。
而且,还有一点,不管我是用.还是$,不管内部耿达是不是static,都可以,继承Button也试了,但是就是没有Text。
还是在这里【http://stackoverflow.com/questio ... -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/questio ... ference-in-xml-file
我是平方X~
回复

使用道具 举报

414

主题

709

帖子

3657

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3657
QQ
 楼主| 发表于 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~
回复 支持 反对

使用道具 举报

414

主题

709

帖子

3657

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3657
QQ
 楼主| 发表于 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
我是平方X~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|平方X ( 冀ICP备14018164号 )

GMT+8, 2024-11-23 20:42 , Processed in 0.106300 second(s), 22 queries .

技术支持:Powered by Discuz!X3.4  © 2001-2013 Comsenz Inc.

版权所有:Copyright © 2014-2018 平方X www.pingfangx.com All rights reserved.

快速回复 返回顶部 返回列表