final ImageView iv_key = (ImageView) findViewById(R.id.key);
final ImageView iv_unlock = (ImageView) findViewById(R.id.unlock);
iv_key.setOnTouchListener(new OnTouchListener() {
int Y, lastY;
int lastL, lastT, lastR, lastB;
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
lastY = (int) event.getRawY();
Y = lastY;
lastL = view.getLeft();
lastT = view.getTop();
lastR = view.getRight();
lastB = view.getBottom();
break;
case MotionEvent.ACTION_MOVE:
LockScreenActivity.viewPager.
requestDisallowInterceptTouchEvent(true);
int distanceY = (int) event.getRawY() - lastY;
int l = view.getLeft();
int r = view.getRight();
int t = view.getTop() + distanceY;
int b = view.getBottom() + distanceY;
//假如向下滑,碰到unlock图标,unlock变色
if(distanceY > 0 && iv_unlock.getTop() < (view.getBottom()-10)){
iv_unlock.setImageResource(R.drawable.unlock_shape_bg_pressed);
}
// 画出移动中的控件
view.layout(l, t, r, b);
lastY = (int) event.getRawY();
break;
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
找到解决办法了. 把所有图片放在一个 level-list 里, 每个图片不同的level值. 然后在java里用ImageView.setImageLevel(Integer); 来动态改变显示的图片, 就可以了.