gpt4 book ai didi

java - nineoldandroids 库使 View 不稳定

转载 作者:行者123 更新时间:2023-12-01 04:50:07 25 4
gpt4 key购买 nike

private void createnewpattern(final String res) {
final int width, height;
BitmapDrawable image = null;
if (res.equals("")) {
width = bitmap.getWidth();
height = bitmap.getHeight();
} else {
image = (BitmapDrawable) this.getResources().getDrawable(
getResources().getIdentifier(res, "drawable",
getPackageName()));
width = image.getBitmap().getWidth();
height = image.getBitmap().getHeight();
}

ImageView pattern = new ImageView(this);
pattern.setId(startingnumber);
if (res.equals(""))
pattern.setImageBitmap(bitmap);
else
pattern.setImageDrawable(image);
pattern.setScaleType(ScaleType.FIT_CENTER);

pattern.setPadding(width / 4, height / 4, width / 4, height / 4);

final RelativeLayout.LayoutParams patternparam = new RelativeLayout.LayoutParams(
width * 3 / 2, height * 3 / 2);

Random random = new Random();
int rx = random.nextInt((contentimage.getWidth() * 3 / 4)
- contentimage.getWidth() / 4 + 1) + 0;
int ry = random.nextInt((contentimage.getHeight() * 3 / 4)
- contentimage.getHeight() / 4 + 1) + 0;

if (res.equals(""))
patternparam.setMargins(GlobalFunction.leftmargin - width / 4,
GlobalFunction.topmargin - height / 4, 0, 0);
else
patternparam.setMargins(rx, ry, 0, 0);

pattern.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
if (isselected.get(view.getId() - 1001)) {

mScaleDetector.onTouchEvent(event);

mRotateDetector.onTouchEvent(event);

mMoveDetector.onTouchEvent(event);

ImageView imageview = (ImageView) rLayout
.findViewById(selectedid);

ViewHelper.setRotation(imageview, mRotationDegrees);

ViewHelper.setScaleX(imageview, mScaleFactor);
ViewHelper.setScaleY(imageview, mScaleFactor);

ViewHelper.setTranslationX(imageview, mFocusX);
ViewHelper.setTranslationY(imageview, mFocusY);
}

switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
if (!isselected.get(view.getId() - 1001)) {
for (int j = 0; j < isselected.size(); j++) {
isselected.set(j, false);
rLayout.findViewById(1001 + j)
.setBackgroundDrawable(null);
}

selectedid = view.getId();
isselected.set(view.getId() - 1001, true);
view.setBackgroundResource(R.drawable.border);

ImageView imageview = (ImageView) view;
imageview.setScaleType(ScaleType.FIT_CENTER);
imageview.setPadding(width / 4, height / 4, width / 4,
height / 4);

mScaleFactor = ViewHelper.getScaleX(imageview);

mRotationDegrees = ViewHelper.getRotation(imageview);

mFocusX = ViewHelper.getTranslationX(imageview);
mFocusY = ViewHelper.getTranslationY(imageview);
}
break;
}

return true;
}
});

patternframe.addView(pattern, patternparam);

isselected.add(false);
startingnumber++;

action4btn.setBackgroundDrawable(GlobalFunction.backgroundselector(
this, R.drawable.paint_action_4_default,
R.drawable.paint_action_4_selected));
}

private class ScaleListener extends
ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
mScaleFactor *= detector.getScaleFactor();
mScaleFactor = Math.max(0.5f, Math.min(mScaleFactor, 4f));

return true;
}
}

private class OnRotationGestureListener implements
RotationGestureDetector.OnRotationGestureListener {

@Override
public boolean OnRotation(RotationGestureDetector rotationDetector) {
mRotationDegrees -= rotationDetector.getAngle();

return true;
}
}

private class MoveListener extends
MoveGestureDetector.SimpleOnMoveGestureListener {
@Override
public boolean onMove(MoveGestureDetector detector) {
PointF d = detector.getFocusDelta();
mFocusX += d.x;
mFocusY += d.y;

return true;
}
}

我有这个监听器,但有一些错误。

图像的方向也会旋转。

当我旋转 90 度时,我将 Y 向上平移,但图像向左平移 X。

最佳答案

听起来当你旋转 90 度时, View 的方向也会改变,因此 Y 轴变成了用户看到的 X 轴。您能提供实际旋转和平移的Animator代码吗?

关于java - nineoldandroids 库使 View 不稳定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15131652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com