<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/myImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="@android:color/black"
android:src="@drawable/image2" />
<View
android:id="@+id/view_clickable_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#aa000000" />
</RelativeLayout>
我希望在获取坐标后,能够使ImageView(myImage)中的图像小部分可点击。这对我来说很有效。现在,我想要在该图像上获得双指缩放的功能。当我放大时,可点击区域将随着图像一起缩放。
我的问题是,我想要获取ImageView中图像的高度(不包括顶部和底部的黑色空白部分。由于ImageView被设置为与父容器匹配,因此在横屏模式下,图像显示在屏幕中央)。每次我都只能获取到ImageView的高度。
以下是用于获取图像和ImageView高度的代码:
int imagWidth = imageView.getWidth();
int h = imageView.getHeight();
int w = imageView.getDrawable().getIntrinsicWidth();
int imagHeight = imageView.getDrawable().getIntrinsicHeight();
Log.e("height", "Image height" + imagHeight + "\n" + "Imageview height" + h);
根据计算: 图片高度 = 882 ImageView 高度 = 672
ImageView#getDrawable()
方法。 - pskinkgetIntrinsic*
方法,那就尝试将你的Drawable转换为BitmapDrawable并获取Bitmap的大小 - 通过调用BitmapDrawable#getBitmap()
方法来获得。 - pskink