本文整理匯總了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;
}