java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x10
发布日期:2021-09-30 11:34:34
浏览次数:7
分类:技术文章
本文共 1075 字,大约阅读时间需要 3 分钟。
获取自定义view属性的时候 遇到这个问题
int[] arr = new int[] { android.R.attr.layout_width, android.R.attr.layout_height };TypedArray typedArray = context.obtainStyledAttributes(attrs, arr);typedArray.getDimensionPixelSize(1, ViewGroup.LayoutParams.MATCH_PARENT);
如果 android:layout_height="match_parent"
typedArray.getDimensionPixelSize(1, ViewGroup.LayoutParams.MATCH_PARENT);这行代码执行的时候会报异常
java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x10
搞了好久才搞明白0x10的含义
/** * Container for a dynamically typed data value. Primarily used with * {@link android.content.res.Resources} for holding resource values. */public class TypedValue { /** Identifies the start of plain integer values. Any type value * from this to {@link #TYPE_LAST_INT} means the * data field holds a generic integer value. */ public static final int TYPE_FIRST_INT = 0x10;当
layout_height="100dp" 只有该属性的值为具体数值的时候 才不会报异常,这个时候 TypedValued的值类型为TYPE_DIMENSION
/** The data field holds a complex number encoding a * dimension value. */ public static final int TYPE_DIMENSION = 0x05;
转载地址:https://blog.csdn.net/id19870510/article/details/52982311 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年03月23日 21时20分08秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【Leetcode刷题篇】leetcode204 计数质数
2019-04-26
【Leetcode刷题篇】leetcode70 爬楼梯
2019-04-26
【Leetcode刷题篇】leetcode739 每日温度
2019-04-26
【Leetcode刷题篇】leetcode121买卖股票的最佳时机
2019-04-26
【面试篇】Java多线程并发-Java关键字volatile详解
2019-04-26
【面试篇】Java的代理模式-静态代理和动态代理详解
2019-04-26
【面试篇】 Java对象拷贝(对象克隆 对象复制)
2019-04-26
【Leetcode刷题篇】leetcode64 最小路径和
2019-04-26
【Leetcode刷题篇】leetcode79 单词搜索
2019-04-26
【Leetcode刷题篇】leetcode300 最长上升子序列
2019-04-26
【Leetcode刷题篇】leetcode394 字符串解码
2019-04-26
【Leetcode刷题篇】leetcode152 乘积最大数组
2019-04-26
【Leetcode刷题篇】leetcode56 合并区间
2019-04-26
【Leetcode刷题篇】leetcode210 课程表II
2019-04-26
【Leetcode刷题篇】leetcode207 课程表
2019-04-26
【Leetcode刷题篇】leetcode322 零钱兑换
2019-04-26
【Leetcode刷题篇】leetcode437 路径总和III
2019-04-26
【Linux篇】Linux常用命令之性能优化
2019-04-26
【面试篇】JVM体系
2019-04-26
【Leetcode刷题篇】leetcode406 根据身高重建队列
2019-04-26