Я совсем недавно пишу android приложений, и у меня возникла проблема с моим ImageView, так как я не могу отобразить мое полное изображение даже при наличии свободного места на экране. Как будто у моего взгляда есть какое-то левое и правое событие заполнения, если это не так.
Поведение:
Вот моя оригинальная картинка: ![enter image description here](https://i.stack.imgur.com/VoJ67.jpg)
Здесь вы можете увидеть картинку, которая на самом деле отображается на моем экране: ![enter image description here](https://i.stack.imgur.com/rYKaW.jpg)
Как вы можете видеть, моя картинка не отображается полностью up.
Код
Это мой код ImageView:
class DrawableImageView extends ImageView implements FlutterView.OnTouchListener
{
float downx = 0;
float downy = 0;
float upx = 0;
float upy = 0;
boolean draw = false;
Canvas canvas;
Paint paint;
Matrix matrix;
public DrawableImageView(Context context)
{
super(context);
setOnTouchListener(this);
}
public DrawableImageView(Context context, AttributeSet attrs)
{
super(context, attrs);
setOnTouchListener(this);
}
public DrawableImageView(Context context, AttributeSet attrs,
int defStyleAttr)
{
super(context, attrs, defStyleAttr);
setOnTouchListener(this);
}
public void setNewImage(Bitmap alteredBitmap, Bitmap bmp)
{
canvas = new Canvas(alteredBitmap );
paint = new Paint();
paint.setColor(Color.RED);
paint.setStrokeWidth(5);
matrix = new Matrix();
canvas.drawBitmap(bmp, matrix, paint);
setImageBitmap(alteredBitmap);
}
public void setDraw(boolean newvalue) {
draw = newvalue;
this.postInvalidate();
}
@Override
public boolean onTouch(View v, MotionEvent event)
{
int action = event.getAction();
if(draw) {
switch (action)
{
case MotionEvent.ACTION_DOWN:
downx = getPointerCoords(event)[0];//event.getX();
downy = getPointerCoords(event)[1];//event.getY();
break;
case MotionEvent.ACTION_MOVE:
upx = getPointerCoords(event)[0];//event.getX();
upy = getPointerCoords(event)[1];//event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
invalidate();
downx = upx;
downy = upy;
break;
case MotionEvent.ACTION_UP:
upx = getPointerCoords(event)[0];//event.getX();
upy = getPointerCoords(event)[1];//event.getY();
canvas.drawLine(downx, downy, upx, upy, paint);
invalidate();
break;
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
}
return true;
}
final float[] getPointerCoords(MotionEvent e)
{
final int index = e.getActionIndex();
final float[] coords = new float[] { e.getX(index), e.getY(index) };
Matrix matrix = new Matrix();
getImageMatrix().invert(matrix);
matrix.postTranslate(getScrollX(), getScrollY());
matrix.mapPoints(coords);
return coords;
}
}
Вот код моего реального вида:
public class Markup implements PlatformView, MethodChannel.MethodCallHandler {
private MethodChannel methodChannel;
DrawableImageView choosenImageView;
Bitmap alteredBitmap;
private Bitmap bitmap;
Markup(final Context context, int id, Object args, BinaryMessenger messenger, final PluginRegistry.Registrar registrar) {
methodChannel = new MethodChannel(messenger, "plugins.smartapps.flutter_markup/markup_" + id);
methodChannel.setMethodCallHandler(this);
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;
bitmap = BitmapFactory.decodeFile((String) args);
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
choosenImageView = new DrawableImageView(context);
choosenImageView.setMaxWidth(width);
choosenImageView.setMaxHeight(height);
choosenImageView.setAdjustViewBounds(true);
choosenImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
//scaleBitmap(bitmap);
alteredBitmap = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getWidth(), bitmap.getConfig());
choosenImageView.setNewImage(alteredBitmap, bitmap);
}
@Override
public View getView() {
return choosenImageView;
}
@Override
public void dispose() {
}
}
Я давно знаю свой пост, но у кого-то есть идея, почему это происходит?
Спасибо!