本文整理汇总了Java中android.widget.ImageView.getLocationOnScreen方法的典型用法代码示例。如果您正苦于以下问题:Java ImageView.getLocationOnScreen方法的具体用法?Java ImageView.getLocationOnScreen怎么用?Java ImageView.getLocationOnScreen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.ImageView
的用法示例。
在下文中一共展示了ImageView.getLocationOnScreen方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertTargetInfo
import android.widget.ImageView; //导入方法依赖的package包/类
void convertTargetInfo(ImageView tarView, Context context) {
if (tarView == null || tarView.getDrawable() == null) {
throw new NullPointerException("target ImageView or ImageView drawable must not null");
}
//get target ImageView info
tarView.getImageMatrix().getValues(mTargetValues);
Rect tarRect = tarView.getDrawable().getBounds();
mTargetWidth = (int) (tarRect.width() * mTargetValues[Matrix.MSCALE_X]);
mTargetHeight = (int) (tarRect.height() * mTargetValues[Matrix.MSCALE_Y]);
mTargetViewWidth = tarView.getWidth();
mTargetViewHeight = tarView.getHeight();
tarView.getLocationOnScreen(mTargetLocation);
init(context);
}
示例2: convertOriginalInfo
import android.widget.ImageView; //导入方法依赖的package包/类
public void convertOriginalInfo(ImageView oriView) {
if (oriView == null || oriView.getDrawable() == null) {
throw new NullPointerException("original ImageView or ImageView drawable must not null");
}
//get original ImageView info
oriView.getImageMatrix().getValues(mOriginalValues);
Rect oriRect = oriView.getDrawable().getBounds();
mOriginalWidth = (int) (oriRect.width() * mOriginalValues[Matrix.MSCALE_X]);
mOriginalHeight = (int) (oriRect.height() * mOriginalValues[Matrix.MSCALE_Y]);
mOriginalViewWidth = oriView.getWidth();
mOriginalViewHeight = oriView.getHeight();
oriView.getLocationOnScreen(mOriginalLocation);
}
示例3: getDisplayedImageLocation
import android.widget.ImageView; //导入方法依赖的package包/类
/**
* Returns the bitmap position inside an imageView.
*
* @param imageView source ImageView
*
* @return 0: left, 1: top, 2: width, 3: height
*/
public static int[] getDisplayedImageLocation(ImageView imageView) {
int[] ret = new int[4];
if (imageView == null || imageView.getDrawable() == null)
return ret;
// Get image dimensions
// Get image matrix values and place them in an array
float[] f = new float[9];
imageView.getImageMatrix().getValues(f);
// Extract the scale values using the constants (if aspect ratio maintained, scaleX == scaleY)
final float scaleX = f[Matrix.MSCALE_X];
final float scaleY = f[Matrix.MSCALE_Y];
// Get the drawable (could also get the bitmap behind the drawable and getWidth/getHeight)
final Drawable d = imageView.getDrawable();
final int origW = d.getIntrinsicWidth();
final int origH = d.getIntrinsicHeight();
// Calculate the actual dimensions
final int actW = Math.round(origW * scaleX);
final int actH = Math.round(origH * scaleY);
ret[2] = actW;
ret[3] = actH;
// Get image position
// We assume that the image is centered into ImageView
int imgViewW = imageView.getWidth();
int imgViewH = imageView.getHeight();
int[] imgViewScreenLoc = new int[2];
imageView.getLocationOnScreen(imgViewScreenLoc);
// get the actual image location inside its image view
int left = imgViewScreenLoc[0] + (imgViewW - actW) / 2;
int top = imgViewScreenLoc[1] + (imgViewH - actH) / 2;
ret[0] = left;
ret[1] = top;
return ret;
}