android 图片点击变暗的另一种办法
来源:互联网 发布:linux安装软件 编辑:程序博客网 时间:2024/05/17 03:07
图片点击变暗的效果 一般情况下都是用两张图片 一张原图一张变暗后的图片 通过selector android:state_pressed 判断是点击还是非点击来切换图片。
这个方法确实很好用,但是后来设想 很多地图图片都需要点击效果 如果用这个方法的话 那是不是需要往项目中添加大量重复的图片而仅仅是改变了明暗。而增加了项目的大小。
于是我决定用一张图片来实现变暗的效果 图片的ontouch事件中去处理 当action为down的时候让图片添加灰度, action为up的时候再改为white
代码如下:
import android.graphics.PorterDuff
final ImageView image = (ImageView) findViewById(R.id.image); final Drawable drawable = getResources().getDrawable(R.drawable.abc); image.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {if(event.getAction() == MotionEvent.ACTION_DOWN){Log.e("suo", "down");drawable.setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);image.setBackgroundDrawable(drawable);}else if(event.getAction() == MotionEvent.ACTION_MOVE){Log.e("suo", "move");}else if(event.getAction() == MotionEvent.ACTION_UP){Log.e("suo", "up");drawable.setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY);image.setBackgroundDrawable(drawable);}return false;}});
- android 图片点击变暗的另一种办法
- Android:实现点击图片时图片变暗的效果
- Android的GridView控件点击图片变暗效果
- Android的GridView控件点击图片变暗效果
- 点击图片变暗效果 省去一张点击效果的图片
- Android 类似IPhone图片点击效果实现,点击logo变暗
- android 按钮点击上去的变暗效果
- Android中ImageView的点击变暗效果
- Android中ImageView的点击变暗效果
- 安卓点击图片变暗,出现点击的效果
- Android:通过滤镜实现点击图片变暗效果
- Android:通过滤镜实现点击图片变暗效果
- 仿微信朋友圈点击图片变暗
- [android]_[ImageView点击变暗]
- Android 多次点击的另一种思路
- Android,自定义一个点击变暗效果的ImageView
- 点击可变暗的ImageView
- 点击图片或者鼠标划过切换样式的另一种写法
- Android是什么 之三手机之硬件形态
- Readonly与Disable的区别
- Android利用SparseArray替换使用HashMap<Integer,E>
- CSS中的position:relative;的作用
- CentOS源码安装 apache2.2.5
- android 图片点击变暗的另一种办法
- 访问网站提示“应用程序脱机”
- (用树结构支持并查集8.2.2)POJ 1703 Find them, Catch them(并查集的简单使用: 判断两个元素是否属于同一集合)
- IOS--启动其他应用程序
- tomcat 调优
- 不是技术牛人,如何拿到国内IT巨头的Offer
- 更新git上fork来代码的方法
- 美国官网入手T-Mobile contract-free后续
- 可以处理负权的单源最短路径的SPFA算法带图详解(自己画的图)