- 浏览: 419409 次
- 性别:
- 来自: 深圳/湛江
文章分类
最新评论
-
wangyudong:
很多API doc生成工具生成doc需要重度依赖代码里加注解的 ...
[ios]利用xcode自动生成项目文档 -
tiger1819:
有源码么,想学习
[android]仿360状态,类流量监控桌面浮动显示 -
119568242:
借我一双翅膀 写道大哥,求指教啊?
IOS 开发,调用打电话,发短信,打开网址 -
借我一双翅膀:
大哥,求指教啊
IOS 开发,调用打电话,发短信,打开网址 -
li247276297:
楼主 是不是要加个权限?
[android]仿360状态,类流量监控桌面浮动显示
研究了下以前不怎么用到的动画效果的实现
顺便做了一个新浪微博消息页面 图标切换动画 效果的实例
如图
然后封装了一下这个效果的实现代码
如下
package com.lurencun.unit.unit; import android.app.Activity; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.widget.ImageView; /** * 标签切换对应动画效果实现类 * * @author poolo * @since 2012年8月10日 * @version 1.0.0 完成了2,3,4个标签的情况下的处理(越多- -就要以笛卡尔积的数量增长- -我觉得呢2~4够用了) */ public class Unit { private int current = 0; private Activity at; private ImageView cursor; private float bmpW; private float screenW; private float offset;// 偏移量 /** * * @param a * 当前Activity * @param layoutId * 当前作为图标使用的ImageViewId * @param drawId * 当前图标的drawId * @param num * 当前标签个数 */ public Unit(Activity a, int viewId, int drawId, int num) { at = a; init(viewId, drawId, num); } /** * 纯粹是为了好看些的一个初始化数据包 无视这里吧 * * @param viewId * @param drawId * @param num */ private void init(int viewId, int drawId, int num) { cursor = (ImageView) at.findViewById(viewId); bmpW = BitmapFactory.decodeResource(at.getResources(), drawId) .getWidth(); screenW = at.getWindowManager().getDefaultDisplay().getWidth(); offset = (screenW / num - bmpW) / 2; Matrix matrix = new Matrix(); matrix.postTranslate(offset, 0); cursor.setImageMatrix(matrix); } /** * 两个标签的情况 * @param selectId 被选中的id */ public void move2tag(int selectId) { Animation animation = null; float zero = 0; float one = offset * 2 + bmpW; switch (selectId) { case 0: if (current == 1) { animation = new TranslateAnimation(one, zero, 0, 0); } break; case 1: if (current == 0) { animation = new TranslateAnimation(zero, one, 0, 0); } break; } current = selectId; animation.setFillAfter(true); animation.setDuration(300); cursor.startAnimation(animation); } /** * 三个标签的情况 * @param selectId 被选中的id */ public void move3tag(int selectId) { Animation animation = null; float zero = 0; float one = offset * 2 + bmpW; float two = one * 2; switch (selectId) { case 0: if (current == 1) { animation = new TranslateAnimation(one, zero, 0, 0); } if (current == 2) { animation = new TranslateAnimation(two, zero, 0, 0); } break; case 1: if (current == 0) { animation = new TranslateAnimation(zero, one, 0, 0); } if (current == 2) { animation = new TranslateAnimation(two, one, 0, 0); } break; case 2: if (current == 0) { animation = new TranslateAnimation(zero, two, 0, 0); } if (current == 1) { animation = new TranslateAnimation(one, two, 0, 0); break; } } current = selectId; animation.setFillAfter(true); animation.setDuration(300); cursor.startAnimation(animation); } /** * 四个标签的情况 * @param selectId 被选中的id */ public void move4tag(int selectId) { Animation animation = null; float zero = 0; float one = offset * 2 + bmpW; float two = one * 2; float three = one * 3; switch (selectId) { case 0: if (current == 1) { animation = new TranslateAnimation(one, zero, 0, 0); } if (current == 2) { animation = new TranslateAnimation(two, zero, 0, 0); } if (current == 3) { animation = new TranslateAnimation(three, zero, 0, 0); } break; case 1: if (current == 0) { animation = new TranslateAnimation(zero, one, 0, 0); } if (current == 2) { animation = new TranslateAnimation(two, one, 0, 0); } if (current == 3) { animation = new TranslateAnimation(three, one, 0, 0); } break; case 2: if (current == 0) { animation = new TranslateAnimation(zero, two, 0, 0); } if (current == 1) { animation = new TranslateAnimation(one, two, 0, 0); } if (current == 3) { animation = new TranslateAnimation(three, two, 0, 0); } break; case 3: if (current == 0) { animation = new TranslateAnimation(zero, three, 0, 0); } if (current == 1) { animation = new TranslateAnimation(one, three, 0, 0); } if (current == 2) { animation = new TranslateAnimation(two, three, 0, 0); } break; } current = selectId; animation.setFillAfter(true); animation.setDuration(300); cursor.startAnimation(animation); } }
一个需要注意的地方 使用此方法的童鞋 切记自己的ImageView需要设置 android:scaleType="matrix" 才能使图形作为矩形计算 不至于出现错误
<ImageView android:id="@+id/testImg1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:contentDescription="@string/hello" android:scaleType="matrix" android:src="@drawable/jian_tou" />
部分借鉴与:http://www.eoeandroid.com/code/2012/0322/994_2.html
另如果路过的同学知道如何截android手机上的动态图麻烦留言告知下,谢谢。
jar包,源码,apk,截图都在下面。
已经交给团队封装代码的童鞋 将会封装到这个工具jar中
https://github.com/chenyoca/ToolkitForAndroid
发表评论
-
[android]使用 Matrix 的随触摸旋转的ImageView
2013-02-22 01:58 7858使用 Matrix 的随触摸旋转的ImageView 突 ... -
[android]动态改变按钮背景状态 StateListDrawable
2012-10-29 10:52 1421动态改变按钮背景状态 很少用到 上次和六哥聊到。 ... -
[android]ViewPage上无法通过onKeyDown()获得按钮事件
2012-08-20 04:53 1326系统无法监听到遥控器在VewPage上的按钮事件,如需 ... -
[android]待解决 lisTview 的onItemSelected 监听事件焦点的问题。
2012-08-18 21:18 2131今天遇到个问题 到目前为止 一直不理解为什么 大概描述下布局 ... -
[android]layout_weight 在layout_width 为fill_parent 与wrap_content 时的不同含义
2012-08-12 12:52 1233转自:http://hi.baidu.com/l ... -
[android]仿制新浪微博消息页面 图标切换动画
2012-08-10 17:33 3研究了下以前不怎么用到的动画效果的实现 顺便做了一个新浪微 ... -
[android]仿制新浪微博消息页面 图标切换动画
2012-08-10 17:33 0研究了下以前不怎么用到的动画效果的实现 顺便做了一个新浪微 ... -
[android]Activity切换动画
2012-08-10 12:23 1441今天准备比赛的时候 遇到了这个问题。 查了些资料 ... -
android中ADT版本问题:无故报 java.lang.NoClassDefFoundError
2012-07-31 22:08 1740今天修改一个老项目的时候,发现在所有配置正确的情况下,代目无任 ... -
[android]仿360状态,类流量监控桌面浮动显示
2012-05-27 22:03 5971前两天看到部分音频播放器可以实现在桌面上显示歌词,360那个浮 ... -
[转]android开发问题记录 "founderapp"
2012-02-08 10:48 1025这段时间,由于某种原因,一直在做android手机开发, ... -
关于weight
2012-02-05 21:20 804layout_weight=1后,除了其它的控件之外剩 ... -
判断SD卡是否存在
2012-02-02 17:54 832android.os.Environment.getEx ... -
[转]Android文件管理器介绍
2012-02-02 16:50 3040转自:http://www.linuxidc.com/L ... -
[转]Android文件管理器介绍
2012-02-02 16:49 5转自:http://www.linuxidc.com/L ... -
[转]android 几何图形的绘制
2012-02-01 16:06 2140转自:http://byandby.iteye.c ... -
Android菜鸟日记32-游戏中的碰撞
2012-01-11 23:09 1717Android菜鸟日记 32-游戏中的碰撞 一、 ... -
Android菜鸟日记31-selector 中使用 shape
2012-01-11 23:05 1551Android菜鸟日记 31- ... -
Android菜鸟日记30-View与SurfaceView
2012-01-11 22:45 906Android菜鸟日记 30 View与Surfa ... -
[转]Android开发者指南-Manifest.xml-activity[原创译文]
2012-01-10 17:55 904<activity android:allowTa ...
相关推荐
自己做的仿新浪微博,给其他童鞋下载借鉴,如有问题,请自便。
简单的仿新浪微博发布评论js代码是一款非常简洁实用的评论发布系统,兼容ie8浏览器。
仿制的新浪微博 功能 使用ASI访问微博接口 简单的换肤功能 发送文字微博功能 下拉刷新最新微博 提示未读微博数量 发送带地理位置的微博 选择地理位置时查询附近的地点 扫描二维码(此功能需要在真机查看) 开发...
利用android的listview仿制的新闻列表,
利用android studio,结合sdk,jdk制作的一个静态qq界面,仅供新手学习交流。
android 仿制ios 屏幕数字解锁
android仿制应用宝的应用详情页.zip
本文档仅有仿制android QQ说明 app在另一个资源 服务器在其他资源 资源下载
Bootstrap仿制CSDN用户主页页面
仿制android QQ 的服务器 app在另一个项目 请自由下载
Android项目源码仿QQ毕设包括论文开题报告服务器数
仿制android QQ app的app 服务器在另一个项目 请自由下载
番剧页面的布局和数据加载。 导航栏的布局。 视频操作按钮的调整。 直播功能的实现。 项目中使用的第三方类库 okhttp3: 3.4.1 retrofit2: 2.1.0 rxjava: 1.1.8 rxandroid: 1.2.1 butterknife: 8.2
仿制Android手机手势解锁,可以高度定制. 简单轻量,使用方便,通过block返回密码 项目git地址:https://github.com/MemoryFate/MGestureSecurity
html仿制咸鱼严选手机端页面网页设计作业 仿咸鱼的html小程序页面 网页设计作业咸鱼严选手机端页面html仿制咸鱼手机端页面仿制小程序咸鱼严选手机端页面
HTML5 css3实现安卓小人图标,动画版的Android图标,那个图标会动的,会旋转,会伸胳膊,呵呵,很强大。CSS3超强大哦,甚至可以用它来制造出一个漂亮的图标来,不相信就下载本HTML5代码一看究竟,仿制出Android安卓...
网页设计作业网易严选手机端页面html仿制网易严选手机端页面仿制小程序网易严选手机端页面
Android应用源码仿制PhotoShop的调色板是一款仿制PhotoShop的调色板源码。代码主要使用了自定义view视图和Drawable。对自定义view,和drawable不了解的这是 一个很好的例子。代码中很对方法都加了注释,可选择用手指...
仿网易新闻客户端源码 android 版 只供学习交流用,
Android应用源码仿制PhotoShop的调色板是一款仿制PhotoShop的调色板源码。代码主要使用了自定义view视图和Drawable。对自定义view,和drawable不了解的这是 一个很好的例子。代码中很对方法都加了注释,可选择用手指...