我有一个RelativeLayout布局,其中包含一个自定义的ImageView,其scaleType属性为"centerInside",我加载了一张位图(通常比imageView小)。如何获取位图绘制的左上角位置?我需要能够在相对于位图位置的顶部/左侧添加视图。
解决方案:可以使用ImageView的getImageMatrix()方法获取绘制位图的矩阵,然后通过Matrix的mapRect方法将ImageView中的矩形映射到位图坐标系中,从而得到位图的位置信息。
RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.scroll_scaled, container, false);
ContentImageView image = (ContentImageView) view.findViewById(R.id.base_page);
Bitmap bm = mInterfaceActivity.getPageImage(mPageNumber);
image.setImageBitmap(bm);`
布局文件 scrolled_scaled
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:scaleType="centerInside"
android:id="@+id/base_page"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff00ff00"
android:contentDescription="@string/product_page"
android:src="@android:drawable/ic_menu_report_image" >
</ImageView>
</RelativeLayout>
test == null
还是test.getDrawable() == null
)。 - Fr33dan