表情符号在缩放 TextView 时变得不可见
Emoji gets Invisible on scaling of TextView
我有文本视图,当我在其中添加表情符号并对其进行缩放时,我的表情符号消失了,只有文本保留在缩放后的文本视图中。
private class ScaleGestureListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
private float mPivotX;
private float mPivotY;
private Vector2D mPrevSpanVector = new Vector2D();
@Override
public boolean onScaleBegin(View view, ScaleGestureDetector detector) {
mPivotX = detector.getFocusX();
mPivotY = detector.getFocusY();
mPrevSpanVector.set(detector.getCurrentSpanVector());
return true;
}
@Override
public boolean onScale(View view, ScaleGestureDetector detector) {
TransformInfo info = new TransformInfo();
info.deltaScale = isScaleEnabled ? detector.getScaleFactor() : 1.0f;
info.deltaAngle = isRotateEnabled ? Vector2D.getAngle(mPrevSpanVector, detector.getCurrentSpanVector()) : 0.0f;
info.deltaX = isTranslateEnabled ? detector.getFocusX() - mPivotX : 0.0f;
info.deltaY = isTranslateEnabled ? detector.getFocusY() - mPivotY : 0.0f;
info.pivotX = mPivotX;
info.pivotY = mPivotY;
info.minimumScale = minimumScale;
info.maximumScale = maximumScale;
// ((ImageEditingActivity) context).setScalingInfo(info,view,-1,view.getTranslationX(),view.getTranslationY());
move(view, info);
return false;
}
}
public void move(View view, TransformInfo info) {
computeRenderOffset(view, info.pivotX, info.pivotY);
adjustTranslation(view, info.deltaX, info.deltaY, view.getTranslationX(), view.getTranslationY());
float scale = view.getScaleX() * info.deltaScale;
scale = Math.max(info.minimumScale, Math.min(info.maximumScale, scale));
view.setScaleX(scale);
view.setScaleY(scale);
if (view.getTag() != null && view.getTag() instanceof TextLabelModel) {
TextLabelModel model = (TextLabelModel) view.getTag();
model.setScaleFactor(scale);
} else {
TextLabelModel model = new TextLabelModel();
model.setScaleFactor(scale);
view.setTag(model);
}
float rotation = adjustAngle(view.getRotation() + info.deltaAngle);
view.setRotation(rotation);
}
public void adjustTranslation(View view, float deltaX, float deltaY, float translationX, float translationY) {
float[] deltaVector = {deltaX, deltaY};
view.getMatrix().mapVectors(deltaVector);
view.setTranslationX(translationX + deltaVector[0]);
view.setTranslationY(translationY + deltaVector[1]);
}
我也有这个问题,通过设置解决
textView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
有关详细信息,请访问这些链接
Why imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); and <application android:hardwareAccelerated="false" have different effect?
https://developer.android.com/guide/topics/graphics/hardware-accel.html
我有文本视图,当我在其中添加表情符号并对其进行缩放时,我的表情符号消失了,只有文本保留在缩放后的文本视图中。
private class ScaleGestureListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
private float mPivotX;
private float mPivotY;
private Vector2D mPrevSpanVector = new Vector2D();
@Override
public boolean onScaleBegin(View view, ScaleGestureDetector detector) {
mPivotX = detector.getFocusX();
mPivotY = detector.getFocusY();
mPrevSpanVector.set(detector.getCurrentSpanVector());
return true;
}
@Override
public boolean onScale(View view, ScaleGestureDetector detector) {
TransformInfo info = new TransformInfo();
info.deltaScale = isScaleEnabled ? detector.getScaleFactor() : 1.0f;
info.deltaAngle = isRotateEnabled ? Vector2D.getAngle(mPrevSpanVector, detector.getCurrentSpanVector()) : 0.0f;
info.deltaX = isTranslateEnabled ? detector.getFocusX() - mPivotX : 0.0f;
info.deltaY = isTranslateEnabled ? detector.getFocusY() - mPivotY : 0.0f;
info.pivotX = mPivotX;
info.pivotY = mPivotY;
info.minimumScale = minimumScale;
info.maximumScale = maximumScale;
// ((ImageEditingActivity) context).setScalingInfo(info,view,-1,view.getTranslationX(),view.getTranslationY());
move(view, info);
return false;
}
}
public void move(View view, TransformInfo info) {
computeRenderOffset(view, info.pivotX, info.pivotY);
adjustTranslation(view, info.deltaX, info.deltaY, view.getTranslationX(), view.getTranslationY());
float scale = view.getScaleX() * info.deltaScale;
scale = Math.max(info.minimumScale, Math.min(info.maximumScale, scale));
view.setScaleX(scale);
view.setScaleY(scale);
if (view.getTag() != null && view.getTag() instanceof TextLabelModel) {
TextLabelModel model = (TextLabelModel) view.getTag();
model.setScaleFactor(scale);
} else {
TextLabelModel model = new TextLabelModel();
model.setScaleFactor(scale);
view.setTag(model);
}
float rotation = adjustAngle(view.getRotation() + info.deltaAngle);
view.setRotation(rotation);
}
public void adjustTranslation(View view, float deltaX, float deltaY, float translationX, float translationY) {
float[] deltaVector = {deltaX, deltaY};
view.getMatrix().mapVectors(deltaVector);
view.setTranslationX(translationX + deltaVector[0]);
view.setTranslationY(translationY + deltaVector[1]);
}
我也有这个问题,通过设置解决
textView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
有关详细信息,请访问这些链接
Why imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); and <application android:hardwareAccelerated="false" have different effect?
https://developer.android.com/guide/topics/graphics/hardware-accel.html