效果:
本效果是触摸事件实现
代码实现:
LinearLayout llt = new LinearLayout(this);
llt.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.setBackgroundColor(Color.parseColor("#F5F5F5"));
if(event.getAction() == MotionEvent.ACTION_UP)
v.setBackgroundColor(Color.parseColor("#ffffff"));
return false;
}
});
PS: 屏幕背景为白色 LinearLayout为一个屏幕中的item,item边框黑灰色效果最佳。可根据自己的item色调进行配色,来达到最佳效果
知识点:
1.setOnTouchListener 中的 onTouch 触发事件的各个行为状态 、坐标
MotionEvent Action 此效果用到 .ACTION_MOVE(间接用到默认) ,ACTION_UP 还有一些常用的 ACTION_DOWN、ACTION_CANCEL等等
MotionEvent event 获得触摸屏幕坐标位置 event.getX()、event.getY() 等等