我的应用程序想要在imageview上的特定位置显示一些视图,图片的大小可能超出屏幕,它也可以移动和缩放。键是标记视图应该与imageview一致,但是大小不是scaled.just like Google map上的标记。
1 首先,我使用FrameLayout.addView(view,LayoutParam),但我标记的点是相对于屏幕而不是imageview。
2 然后我用Canvas将标记的视图放在imageview中,但标记的视图用imageview缩放,代码是
ziv = (MyZoomImageView) findViewById(R.id.imageView); ziv.setScaleType(ImageView.ScaleType.CENTER); Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.iv_test).copy(Bitmap.Config.ARGB_8888, true); ziv.setImageBitmap(bitmap); // put the imageview as a canvas Canvas canvas = new Canvas(bitmap); bm_click_on = BitmapFactory.decodeResource(getResources(),> R.mipmap.iv_sandmap_building_on); bm_click_off = BitmapFactory.decodeResource(getResources(), R.mipmap.iv_sandmap_building_off); mPaint = new Paint(); canvas.drawBitmap(bm_click_on, 200, 200, mPaint);// add marked view canvas.drawBitmap(bm_click_off, 950, 400, mPaint);// add marked view