Java Code Examples for android.widget.ImageView#getGlobalVisibleRect()

The following examples show how to use android.widget.ImageView#getGlobalVisibleRect() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private Rect getDrawableBoundsInView(ImageView iv) {
    if (iv != null && iv.getDrawable() != null) {
        Drawable d = iv.getDrawable();
        Rect result = new Rect();
        iv.getGlobalVisibleRect(result);
        Rect tDrawableRect = d.getBounds();
        Matrix drawableMatrix = iv.getImageMatrix();
        float[] values = new float[9];
        if (drawableMatrix != null) {
            drawableMatrix.getValues(values);
        }

        result.left += (int) values[2];
        result.top += (int) values[5];
        result.right = (int) ((float) result.left + (float) tDrawableRect.width() * (values[0] == 0.0F ? 1.0F : values[0]));
        result.bottom = (int) ((float) result.top + (float) tDrawableRect.height() * (values[4] == 0.0F ? 1.0F : values[4]));
        return result;
    } else {
        return null;
    }
}
 
Example 2
/**
 * 查找信息
 * 从第一个完整可见item逆序遍历,如果初始位置为0,则不执行方法内循环
 */
private void computeBoundsBackward(int firstCompletelyVisiblePos) {
    for (int i = firstCompletelyVisiblePos;i < mThumbViewInfoList.size(); i++) {
        View itemView = mGridLayoutManager.findViewByPosition(i);
        Rect bounds = new Rect();
        if (itemView != null) {
            ImageView thumbView = (ImageView) itemView.findViewById(R.id.iv);
            thumbView.getGlobalVisibleRect(bounds);
        }
        mThumbViewInfoList.get(i).setBounds(bounds);
    }
}
 
Example 3
/**
 * 查找信息
 * 从第一个完整可见item逆序遍历,如果初始位置为0,则不执行方法内循环
 */
private void computeBoundsBackward(int firstCompletelyVisiblePos) {
    for (int i = firstCompletelyVisiblePos;i < mThumbViewInfoList.size(); i++) {
        View itemView = listView.getChildAt(i-firstCompletelyVisiblePos);
        Rect bounds = new Rect();
        if (itemView != null) {
            ImageView thumbView = (ImageView) itemView.findViewById(R.id.iv);
            thumbView.getGlobalVisibleRect(bounds);
        }
        mThumbViewInfoList.get(i).setBounds(bounds);
    }
}
 
Example 4
/**
 * 查找信息
 * 从第一个完整可见item逆序遍历,如果初始位置为0,则不执行方法内循环
 */
private void computeBoundsBackward(int firstCompletelyVisiblePos) {
    for (int i = firstCompletelyVisiblePos; i < mThumbViewInfoList.size(); i++) {
        View itemView = listView.getChildAt(i - firstCompletelyVisiblePos);
        Rect bounds = new Rect();
        if (itemView != null) {
            ImageView thumbView = (ImageView) itemView.findViewById(R.id.iv);
            thumbView.getGlobalVisibleRect(bounds);
        }
        mThumbViewInfoList.get(i).setBounds(bounds);
    }
}
 
Example 5
Source Project: ZoomPreviewPicture   File: PostAdapter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 查找信息
 * @param list 图片集合
 */
private void computeBoundsBackward(List<UserViewInfo> list) {
    for (int i = 0;i < mNglContent.getChildCount(); i++) {
        View itemView = mNglContent.getChildAt(i);
        Rect bounds = new Rect();
        if (itemView != null) {
            ImageView thumbView = (ImageView) itemView;
            thumbView.getGlobalVisibleRect(bounds);
        }
        list.get(i).setBounds(bounds);
        list.get(i).setUrl(list.get(i).getUrl());
    }

}
 
Example 6
/**
 * 查找信息
 * 从第一个完整可见item逆序遍历,如果初始位置为0,则不执行方法内循环
 */
private void computeBoundsBackward(int firstCompletelyVisiblePos) {
    for (int i = firstCompletelyVisiblePos; i < mThumbViewInfoList.size(); i++) {
        View itemView = listView.getChildAt(i - firstCompletelyVisiblePos);
        Rect bounds = new Rect();
        if (itemView != null) {
            //需要显示过度控件
            ImageView thumbView = (ImageView) itemView.findViewById(R.id.iv);
            //拿到在控件屏幕可见中控件显示为矩形Rect信息
            thumbView.getGlobalVisibleRect(bounds);
        }
        mThumbViewInfoList.get(i).setBounds(bounds);
    }
}
 
Example 7
/**
 * 查找信息
 * 从第一个完整可见item逆序遍历,如果初始位置为0,则不执行方法内循环
 */
private void computeBoundsBackward(int firstCompletelyVisiblePos) {
    for (int i = firstCompletelyVisiblePos;i < mThumbViewInfoList.size(); i++) {
        View itemView = mGridLayoutManager.findViewByPosition(i);
        Rect bounds = new Rect();
        if (itemView != null) {
            ImageView thumbView =  itemView.findViewById(R.id.iv);
            thumbView.getGlobalVisibleRect(bounds);
        }
        mThumbViewInfoList.get(i).setBounds(bounds);
    }
}
 
Example 8
public static Rect getBitmapRectFromImageView(ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    Bitmap bitmap = null;
    if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }

    Rect rect = new Rect();
    boolean isVisible = imageView.getGlobalVisibleRect(rect);
    if (!isVisible) {
        int[] location = new int[2];
        imageView.getLocationOnScreen(location);

        rect.left = location[0];
        rect.top = location[1];
        rect.right = rect.left + imageView.getWidth();
        rect.bottom = rect.top + imageView.getHeight();
    }

    if (bitmap != null) {

        int bitmapWidth = bitmap.getWidth();
        int bitmapHeight = bitmap.getHeight();

        int imageViewWidth = imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
        int imageviewHeight = imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();

        float startScale;
        if ((float) imageViewWidth / bitmapWidth > (float) imageviewHeight / bitmapHeight) {
            // Extend start bounds horizontally
            startScale = (float) imageviewHeight / bitmapHeight;

        } else {
            startScale = (float) imageViewWidth / bitmapWidth;

        }

        bitmapHeight = (int) (bitmapHeight * startScale);
        bitmapWidth = (int) (bitmapWidth * startScale);

        int deltaX = (imageViewWidth - bitmapWidth) / 2;
        int deltaY = (imageviewHeight - bitmapHeight) / 2;

        rect.set(rect.left + deltaX, rect.top + deltaY, rect.right - deltaX, rect.bottom - deltaY);

        return rect;
    } else {
        return null;
    }

}
 
Example 9
public static Rect getBitmapRectFromImageView(ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    Bitmap bitmap = null;
    if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }

    Rect rect = new Rect();
    boolean isVisible = imageView.getGlobalVisibleRect(rect);
    if (!isVisible) {
        int[] location = new int[2];
        imageView.getLocationOnScreen(location);

        rect.left = location[0];
        rect.top = location[1];
        rect.right = rect.left + imageView.getWidth();
        rect.bottom = rect.top + imageView.getHeight();
    }

    if (bitmap != null) {

        int bitmapWidth = bitmap.getWidth();
        int bitmapHeight = bitmap.getHeight();

        int imageViewWidth = imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
        int imageviewHeight = imageView.getHeight() - imageView.getPaddingTop() - imageView.getPaddingBottom();

        float startScale;
        if ((float) imageViewWidth / bitmapWidth > (float) imageviewHeight / bitmapHeight) {
            // Extend start bounds horizontally
            startScale = (float) imageviewHeight / bitmapHeight;

        } else {
            startScale = (float) imageViewWidth / bitmapWidth;

        }

        bitmapHeight = (int) (bitmapHeight * startScale);
        bitmapWidth = (int) (bitmapWidth * startScale);

        int deltaX = (imageViewWidth - bitmapWidth) / 2;
        int deltaY = (imageviewHeight - bitmapHeight) / 2;

        rect.set(rect.left + deltaX, rect.top + deltaY, rect.right - deltaX, rect.bottom - deltaY);

        return rect;
    } else {
        return null;
    }

}