我已经实现了Sticker Image-view Lib,它的工作完美与缩放缩放删除但我想缩放左/底/上/右特定触摸的图像区域将是缩放和左侧触摸将只留下缩放将只有左右标度,顶部触摸将是销售顶部/底部。
我用过的是什么 https://github.com/kencheung4/android-StickerView 我使用过的这个库。
如果我想为贴纸视图添加四个新动作顶部/底部/左/右动作,该怎么办。
我的触摸式方法是
private OnTouchListener mTouchListener = new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
if(view.getTag().equals("DraggableViewGroup")) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.v(TAG, "sticker view action down");
move_orgX = event.getRawX();
move_orgY = event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
Log.v(TAG, "sticker view action move");
float offsetX = event.getRawX() - move_orgX;
float offsetY = event.getRawY() - move_orgY;
StickerView.this.setX(StickerView.this.getX()+offsetX);
StickerView.this.setY(StickerView.this.getY() + offsetY);
move_orgX = event.getRawX();
move_orgY = event.getRawY();
break;
case MotionEvent.ACTION_UP:
Log.v(TAG, "sticker view action up");
break;
}
}else if(view.getTag().equals("iv_scale")){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.v(TAG, "iv_scale action down");
this_orgX = StickerView.this.getX();
this_orgY = StickerView.this.getY();
scale_orgX = event.getRawX();
scale_orgY = event.getRawY();
scale_orgWidth = StickerView.this.getLayoutParams().width;
scale_orgHeight = StickerView.this.getLayoutParams().height;
rotate_orgX = event.getRawX();
rotate_orgY = event.getRawY();
centerX = StickerView.this.getX()+
((View)StickerView.this.getParent()).getX()+
(float)StickerView.this.getWidth()/2;
//double statusBarHeight = Math.ceil(25 * getContext().getResources().getDisplayMetrics().density);
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
double statusBarHeight = result;
centerY = StickerView.this.getY()+
((View)StickerView.this.getParent()).getY()+
statusBarHeight+
(float)StickerView.this.getHeight()/2;
break;
case MotionEvent.ACTION_MOVE:
Log.v(TAG, "iv_scale action move");
rotate_newX = event.getRawX();
rotate_newY = event.getRawY();
double angle_diff = Math.abs(
Math.atan2(event.getRawY() - scale_orgY , event.getRawX() - scale_orgX)
- Math.atan2(scale_orgY - centerY, scale_orgX - centerX))*180/Math.PI;
Log.v(TAG, "angle_diff: "+angle_diff);
double length1 = getLength(centerX, centerY, scale_orgX, scale_orgY);
double length2 = getLength(centerX, centerY, event.getRawX(), event.getRawY());
int size = convertDpToPixel(SELF_SIZE_DP, getContext());
if(length2 > length1
&& (angle_diff < 25 || Math.abs(angle_diff-180)<25)
) {
//scale up
double offsetX = Math.abs(event.getRawX() - scale_orgX);
double offsetY = Math.abs(event.getRawY() - scale_orgY);
double offset = Math.max(offsetX, offsetY);
offset = Math.round(offset);
StickerView.this.getLayoutParams().width += offset;
StickerView.this.getLayoutParams().height += offset;
onScaling(true);
//DraggableViewGroup.this.setX((float) (getX() - offset / 2));
//DraggableViewGroup.this.setY((float) (getY() - offset / 2));
}else if(length2 < length1
&& (angle_diff < 25 || Math.abs(angle_diff-180)<25)
&& StickerView.this.getLayoutParams().width > size/2
&& StickerView.this.getLayoutParams().height > size/2) {
//scale down
double offsetX = Math.abs(event.getRawX() - scale_orgX);
double offsetY = Math.abs(event.getRawY() - scale_orgY);
double offset = Math.max(offsetX, offsetY);
offset = Math.round(offset);
StickerView.this.getLayoutParams().width -= offset;
StickerView.this.getLayoutParams().height -= offset;
onScaling(false);
}
//rotate
double angle = Math.atan2(event.getRawY() - centerY, event.getRawX() - centerX) * 180 / Math.PI;
Log.v(TAG, "log angle: " + angle);
//setRotation((float) angle - 45);
setRotation((float) angle - 45);
Log.v(TAG, "getRotation(): " + getRotation());
onRotating();
rotate_orgX = rotate_newX;
rotate_orgY = rotate_newY;
scale_orgX = event.getRawX();
scale_orgY = event.getRawY();
postInvalidate();
requestLayout();
break;
case MotionEvent.ACTION_UP:
Log.v(TAG, "iv_scale action up");
break;
}
}
return true;
}
};
有没有人可以帮助我...?