属性动画 自定义属性
2016-06-03 16:07
267 查看
上次说的属性动画的满足条件,其中有一个就是提供了get()/set()方法,来提供让我们对封装起来的属性进行修改。
我们通常知道的类似translationY,translationX,translation,alpha...点暴漏出了可供修改的方法。
这里就明白了,我们可以提供一个包装类,给那些本身没有get()/set()方法的控件提供方法
或者直接给我们自定义类的自身属性提供get()/set()方法,那就完美了。
说个看到过的例子,就像button控件,它的宽度width没有暴露出方法,我们就可以这样
就这样
我们通常知道的类似translationY,translationX,translation,alpha...点暴漏出了可供修改的方法。
这里就明白了,我们可以提供一个包装类,给那些本身没有get()/set()方法的控件提供方法
或者直接给我们自定义类的自身属性提供get()/set()方法,那就完美了。
说个看到过的例子,就像button控件,它的宽度width没有暴露出方法,我们就可以这样
@Override public void onClick(View v) { if (v == mButton) { performAnimate(); } }
private void performAnimate() { ViewWrapper wrapper = new ViewWrapper(mButton); ObjectAnimator.ofInt(wrapper, "width", 500).setDuration(5000).start(); }
private static class ViewWrapper { private View mTarget; public ViewWrapper(View target) { mTarget = target; } public int getWidth() { return mTarget.getLayoutParams().width; } public void setWidth(int width) { mTarget.getLayoutParams().width = width; mTarget.requestLayout(); } }
就这样
相关文章推荐
- 14.2.3 InnoDB Redo Log
- 14.2.3 InnoDB Redo Log
- 原创-兼容IE8的placeholder
- Jira和Confluence集成Crowd实现SSO-构建高效的团队协作工具
- JS 对象与数组的变化监听
- leetcode Remove Duplicates from Sorted List II
- Python 运算符
- 自定义委托
- UNIX网络编程笔记(4)—TCP客户/服务器程序示例
- 华为机试---计算日期到天数转换
- ionic提示/usr/bin/env: node: 没有那个文件或目录
- MyBatis转义
- version `GFORTRAN_1.4' not found (required by /usr/lib/liblapack.so.3) 问题的解决方案
- Ionic如何实现下拉刷新与上拉加载功能
- Spring整合JMS基于ActiveMQ实现
- Java HtmlEmail 邮件发送的简单实现代码
- 重构
- sqlite的数据库
- 谈论谋略
- POJ 1743 后缀数组不重叠最长重复子串