下面列出了android.widget.ImageView#getHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void animateClose(ImageView avatar, Rect ori) {
if (ori == null) {
return;
}
int[] avatarLocation = new int[2];
avatar.getLocationOnScreen(avatarLocation);
final int transX = ori.left - avatarLocation[0];
final int transY = ori.top - avatarLocation[1];
final float scaleX = (float) ori.width() / (float) avatar.getWidth();
final float scaleY = (float) ori.height() / (float) avatar.getHeight();
avatar.animate().translationX(transX).translationY(transY).scaleY(scaleY).scaleX(scaleX).alpha(0.7f).rotationY(0f)
.setDuration(300)
.setListener(new MyAnimationListener(new Runnable() {
@Override
public void run() {
dismissAllowingStateLoss();
}
}));
}
/**
* Window上での描画領域を取得します。
* 当たり判定の矩形を表します。
*
* @param outRect 変更を加えるRect
*/
void getWindowDrawingRect(Rect outRect) {
// Gravityが逆向きなので、矩形の当たり判定も上下逆転(top/bottom)
// top(画面上で下方向)の判定を多めに設定
final ImageView iconView = hasActionTrashIcon() ? mActionTrashIconView : mFixedTrashIconView;
final float iconPaddingLeft = iconView.getPaddingLeft();
final float iconPaddingTop = iconView.getPaddingTop();
final float iconWidth = iconView.getWidth() - iconPaddingLeft - iconView.getPaddingRight();
final float iconHeight = iconView.getHeight() - iconPaddingTop - iconView.getPaddingBottom();
final float x = mTrashIconRootView.getX() + iconPaddingLeft;
final float y = mRootView.getHeight() - mTrashIconRootView.getY() - iconPaddingTop - iconHeight;
final int left = (int) (x - TARGET_CAPTURE_HORIZONTAL_REGION * mMetrics.density);
final int top = -mRootView.getHeight();
final int right = (int) (x + iconWidth + TARGET_CAPTURE_HORIZONTAL_REGION * mMetrics.density);
final int bottom = (int) (y + iconHeight + TARGET_CAPTURE_VERTICAL_REGION * mMetrics.density);
outRect.set(left, top, right, bottom);
}
/**
* 根据当前的状态来旋转箭头。
*/
public static void rotateArrow(ImageView arrow, boolean flag) {
float pivotX = arrow.getWidth() / 2f;
float pivotY = arrow.getHeight() / 2f;
float fromDegrees = 0f;
float toDegrees = 0f;
// flag为true则向下
if (flag) {
fromDegrees = 0f;
toDegrees = 180f;
} else {
fromDegrees = 180f;
toDegrees = 0f;
}
//旋转动画效果 参数值 旋转的开始角度 旋转的结束角度 pivotX x轴伸缩值
RotateAnimation animation = new RotateAnimation(fromDegrees, toDegrees,
pivotX, pivotY);
//该方法用于设置动画的持续时间,以毫秒为单位
animation.setDuration(200);
//动画终止时停留在最后一帧
animation.setFillAfter(true);
//启动动画
arrow.startAnimation(animation);
}
@Override
public void onBindData(int position, @NonNull ImageView convertView) {
int width = convertView.getWidth();
int height = convertView.getHeight();
String imageUrl = datas.get(position);
// 去掉缩略图的url的获取
// 例如 http://resources.appjishu.com/star-sign/463490676928020480.jpg!/fxfn/540x303
// if (width > 0 && height > 0) {
// imageUrl = BmobUrlUtil.getThumbImageUrl(imageUrl, width, height);
// } else {
// imageUrl = BmobUrlUtil.getThumbImageUrl(imageUrl, 25);
// }
KLog.i("处理的url >>> " + imageUrl);
ImageLoadMnanger.INSTANCE.loadImage(convertView, imageUrl);
}
/**
* 根据image设置宽高。如果是wrap_content,match_parent则返回宽高250</br>
*
* @param imageView
* @return
*/
private Point getSize(ImageView imageView) {
Point size = new Point();
if (imageView.getWidth() > 0) {
size.x = imageView.getWidth();
size.y = imageView.getHeight();
} else {
size.x = size.y = 250;
}
return size;
}
void resetSizes(@NonNull ImageView imageView) {
final int imageViewWidth = imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
final int imageViewHeight = imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
if (imageViewWidth == 0 || imageViewHeight == 0) {
return;
}
Drawable drawable = SketchUtils.getLastDrawable(imageView.getDrawable());
if (drawable == null) {
return;
}
final int drawableWidth = drawable.getIntrinsicWidth();
final int drawableHeight = drawable.getIntrinsicHeight();
if (drawableWidth == 0 || drawableHeight == 0) {
return;
}
viewSize.set(imageViewWidth, imageViewHeight);
drawableSize.set(drawableWidth, drawableHeight);
if (drawable instanceof SketchDrawable && !(drawable instanceof SketchLoadingDrawable)) {
SketchDrawable sketchDrawable = (SketchDrawable) drawable;
imageSize.set(sketchDrawable.getOriginWidth(), sketchDrawable.getOriginHeight());
} else {
imageSize.set(drawableWidth, drawableHeight);
}
}
/**
* Defines target size for image. Size is defined by target
* {@link ImageView view} parameters, configuration parameters or device
* display dimensions.<br />
* Size computing algorithm:<br />
* 1) Get the actual drawn <b>getWidth()</b> and <b>getHeight()</b> of the
* View. If view haven't drawn yet then go to step #2.<br />
* 2) Get <b>layout_width</b> and <b>layout_height</b>. If both of them
* haven't exact value then go to step #3.<br />
* 3) Get <b>maxWidth</b> and <b>maxHeight</b>. If both of them are not
* set then go to step #4.<br />
* 4) Get <b>maxImageWidth</b> param (<b>maxImageWidthForMemoryCache</b>)
* and <b>maxImageHeight</b> param (<b>maxImageHeightForMemoryCache</b>).
* If both of them are not set (equal 0) then go to step #5.<br />
* 5) Get device screen dimensions.
*/
public static ImageSize defineTargetSizeForView(ImageView imageView, int maxImageWidth, int maxImageHeight) {
final DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics();
final LayoutParams params = imageView.getLayoutParams();
int width = (params != null && params.width == LayoutParams.WRAP_CONTENT) ? 0 : imageView.getWidth(); // Get
// actual
// image
// width
if (width <= 0 && params != null)
width = params.width; // Get layout width parameter
if (width <= 0)
width = getImageViewFieldValue(imageView, "mMaxWidth"); // Check
// maxWidth
// parameter
if (width <= 0)
width = maxImageWidth;
if (width <= 0)
width = displayMetrics.widthPixels;
int height = (params != null && params.height == LayoutParams.WRAP_CONTENT) ? 0 : imageView.getHeight(); // Get
// actual
// image
// height
if (height <= 0 && params != null)
height = params.height; // Get layout height parameter
if (height <= 0)
height = getImageViewFieldValue(imageView, "mMaxHeight"); // Check
// maxHeight
// parameter
if (height <= 0)
height = maxImageHeight;
if (height <= 0)
height = displayMetrics.heightPixels;
return new ImageSize(width, height);
}
/**
* 箭头旋转动画
*
* @param arrow
* @param flag
*/
public static void rotateArrow(ImageView arrow, boolean flag) {
float pivotX = arrow.getWidth() / 2f;
float pivotY = arrow.getHeight() / 2f;
// flag为true则向上
float fromDegrees = flag ? 180f : 180f;
float toDegrees = flag ? 360f : 360f;
//旋转动画效果 参数值 旋转的开始角度 旋转的结束角度 pivotX x轴伸缩值
RotateAnimation animation = new RotateAnimation(fromDegrees, toDegrees,
pivotX, pivotY);
//该方法用于设置动画的持续时间,以毫秒为单位
animation.setDuration(350);
//启动动画
arrow.startAnimation(animation);
}
public int[] getPreviewSize() {
final ImageView i = (ImageView) findViewById(R.id.widget_preview);
int[] maxSize = new int[2];
maxSize[0] = i.getWidth() - mOriginalImagePadding.left - mOriginalImagePadding.right;
maxSize[1] = i.getHeight() - mOriginalImagePadding.top;
return maxSize;
}
@Override
public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, @NonNull ImageView child, @NonNull View dependency) {
// 计算X轴坐标
if (mOriginalHeaderX == 0) {
this.mOriginalHeaderX = dependency.getWidth() / 2 - child.getWidth() / 2;
}
// 计算Y轴坐标
if (mOriginalHeaderY == 0) {
mOriginalHeaderY = dependency.getHeight() - child.getHeight();
}
//X轴百分比
float mPercentX = dependency.getY() / mOriginalHeaderX;
if (mPercentX >= 1) {
mPercentX = 1;
}
//Y轴百分比
float mPercentY = dependency.getY() / mOriginalHeaderY;
if (mPercentY >= 1) {
mPercentY = 1;
}
float x = mOriginalHeaderX - mOriginalHeaderX * mPercentX;
if (x <= child.getWidth()) {
x = child.getWidth();
}
// TODO 头像的放大和缩小没做
child.setX(x);
child.setY(mOriginalHeaderY - mOriginalHeaderY * mPercentY);
return true;
}
private int getImageViewHeight(ImageView imageView) {
if (null == imageView)
return 0;
return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}
private int getImageViewHeight(ImageView imageView) {
return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}
private int getImageViewHeight(ImageView imageView) {
if (null == imageView)
return 0;
return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}
private int getImageViewHeight(ImageView imageView) {
if (null == imageView)
return 0;
return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}
private int getImageViewHeight(ImageView imageView) {
return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}
private int getImageViewHeight(ImageView imageView) {
if (null == imageView)
return 0;
return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}
private int getImageViewHeight(ImageView imageView) {
if (null == imageView)
return 0;
return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}
private int getImageViewHeight(ImageView imageView) {
return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}
/**
* Asynchronously fulfills the request into the specified {@link ImageView} and invokes the
* target {@link Callback} if it's not {@code null}.
* <p>
* <em>Note:</em> The {@link Callback} param is a strong reference and will prevent your
* {@link android.app.Activity} or {@link android.app.Fragment} from being garbage collected. If
* you use this method, it is <b>strongly</b> recommended you invoke an adjacent
* {@link Picasso#cancelRequest(android.widget.ImageView)} call to prevent temporary leaking.
*/
public void into(@NonNull ImageView target, @Nullable Callback callback) {
long started = System.nanoTime();
checkMain();
if (target == null) {
throw new IllegalArgumentException("Target must not be null.");
}
if (!data.hasImage()) {
picasso.cancelRequest(target);
if (setPlaceholder) {
setPlaceholder(target, getPlaceholderDrawable());
}
return;
}
if (deferred) {
if (data.hasSize()) {
throw new IllegalStateException("Fit cannot be used with resize.");
}
int width = target.getWidth();
int height = target.getHeight();
if (width == 0 || height == 0) {
if (setPlaceholder) {
setPlaceholder(target, getPlaceholderDrawable());
}
picasso.defer(target, new DeferredRequestCreator(this, target, callback));
return;
}
data.resize(width, height);
}
Request request = createRequest(started);
if (shouldReadFromMemoryCache(request.memoryPolicy)) {
Bitmap bitmap = picasso.quickMemoryCacheCheck(request.key);
if (bitmap != null) {
picasso.cancelRequest(target);
Result result = new Result.Bitmap(bitmap, MEMORY);
setResult(target, picasso.context, result, noFade, picasso.indicatorsEnabled);
if (picasso.loggingEnabled) {
log(OWNER_MAIN, VERB_COMPLETED, request.plainId(), "from " + MEMORY);
}
if (callback != null) {
callback.onSuccess();
}
return;
}
}
if (setPlaceholder) {
setPlaceholder(target, getPlaceholderDrawable());
}
Action action = new ImageViewAction(picasso, target, request, errorDrawable, errorResId, noFade,
callback);
picasso.enqueueAndSubmit(action);
}
private int getImageViewHeight(ImageView imageView) {
return imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();
}