现在的移动APP数量繁多,为了提高自己的APP吸睛率,策划和开发人员可以说都是绞尽脑汁玩出新花样。本控件也是为了满足项目需求,特此放上来方便大家及以后自己使用。
这个多功能按钮主要功能是有多个状态,不同状态显示不同的图片,并且还带有闪烁的效果。下面是图和代码。
这个多功能按钮主要功能是有多个状态,不同状态显示不同的图片,并且还带有闪烁的效果。下面是图和代码。
package com.androiddemo; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.util.AttributeSet; import android.view.ViewGroup; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.ImageView; /** * 多功能按钮,各种状态 * * @author leehom * */ public class MultiButton extends ImageView { private Bitmap[] bitmaps; private int index;// 当前状态 private AlphaAnimation alphaAnimation; public MultiButton(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } public int getIndex() { return index; } public void setIndex(int index) { this.index = index; } public void startAnimation() { if (alphaAnimation == null) { alphaAnimation = new AlphaAnimation(0, 1); alphaAnimation.setRepeatCount(Animation.INFINITE); alphaAnimation.setRepeatMode(Animation.REVERSE); alphaAnimation.setDuration(500); } startAnimation(alphaAnimation); } public void stopAnimation() { if (alphaAnimation != null) alphaAnimation.cancel(); if (getAnimation() != null) getAnimation().cancel(); setAnimation(null); } public void prepIndex() { int tempIndex = index; --tempIndex; if (tempIndex >= 0 && tempIndex < bitmaps.length) index = tempIndex; else if (bitmaps != null) index = bitmaps.length - 1; postInvalidate(); } public void nextIndex() { int tempIndex = index; ++tempIndex; if (tempIndex >= 0 && tempIndex < bitmaps.length) index = tempIndex; else index = 0; postInvalidate(); } public void initBitmap(int[] ids) { bitmaps = new Bitmap[ids.length]; for (int i = 0; i < ids.length; i++) { bitmaps[i] = BitmapFactory.decodeResource(getResources(), ids[i]); } ViewGroup.LayoutParams params = getLayoutParams(); if (params != null && bitmaps != null && bitmaps[0] != null) { params.width = bitmaps[0].getWidth(); params.height = bitmaps[0].getWidth(); requestLayout(); } } @Override public void draw(Canvas canvas) { // TODO Auto-generated method stub if (bitmaps != null && index >= 0 && index < bitmaps.length) { canvas.drawBitmap(bitmaps[index], 0, 0, null); } } }
收藏的用户(0) X
正在加载信息~
推荐阅读
最新回复 (0)
站点信息
- 文章2303
- 用户1336
- 访客11160286
每日一句
There is always a better way.
总有更好的办法。
总有更好的办法。
IntelliJ IDEA2018~2019.1激活码-注册码
C++实现NAT检测程序
Google Play商城将85款恶意App下架
打开显示interface.png 或者显示interface.swf
【黑苹果安装】——如何在windows下操作EFI分区
Android简单树状实现
Android 8.0应用图标适配
Android Studio3.4.1更新及槽点
C/C++通过WMI和系统API函数获取系统硬件配置信息
DuiLib编译出错:成员声明中不允许限定名
Java中的(耦合)控制反转
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is
#ifdef _DEBUG失效问题
新会员