Example usage for android.widget ImageView getPaddingLeft

List of usage examples for android.widget ImageView getPaddingLeft

Introduction

In this page you can find the example usage for android.widget ImageView getPaddingLeft.

Prototype

public int getPaddingLeft() 

Source Link

Document

Returns the left padding of this view.

Usage

From source file:Main.java

public static Rect getBitmapRectFromImageView(ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    Bitmap bitmap = null;//from   www.j a va2  s  . c  om
    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;
    }
}

From source file:com.resonos.apps.library.tabviewpager.TabPageIndicator.java

/**
 * Does a bit of calculations to better measure the size of tabs.
 *  This is to fix a bug where text would occasionally get cut off.
 *///from  ww w  .j ava 2s. c  o  m
private void doPreMeasure() {
    TabView tabView = (TabView) mInflater.inflate(R.layout.vpi__tab, null);
    TextView textView = (TextView) tabView.findViewById(android.R.id.text1);
    ImageView imageView = (ImageView) tabView.findViewById(R.id.img);
    mTextPaint = textView.getPaint();
    mTextPadding = textView.getTotalPaddingLeft() + textView.getTotalPaddingRight() + tabView.getPaddingLeft()
            + tabView.getPaddingRight();
    int mImagePadding = imageView.getPaddingLeft() + imageView.getPaddingRight();

    int t = 0;
    int count = getTitleProvider().getCount();
    mAllMinWidths = new int[count];
    String text;
    Drawable d;
    for (int i = 0; i < count; i++) {
        d = getTitleProvider().getIcon(i);
        text = getTitleProvider().getTitle(i);
        if (d != null) {
            mAllMinWidths[i] = d.getIntrinsicWidth() + mImagePadding;
        } else {
            StaticLayout layout = new StaticLayout(text, mTextPaint, MAX_TAB_WIDTH, Alignment.ALIGN_NORMAL,
                    1.0f, 0.0f, false);
            int w = (int) (layout.getLineWidth(0) + 1);
            mAllMinWidths[i] = mTextPadding + w;
        }
        if (getTitleProvider().isVisible(i))
            t += mAllMinWidths[i];
    }
    mTotalMinWidth = t;
}

From source file:com.frank.protean.photoview.PhotoViewAttacher.java

private int getImageViewWidth(ImageView imageView) {
    return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
}

From source file:com.github.lakeshire.photoview.PhotoViewAttacher.java

private int getImageViewWidth(ImageView imageView) {
    if (null == imageView) {
        return 0;
    }/*  w  w  w.jav a  2  s. co  m*/
    return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
}

From source file:baizhuan.hangzhou.com.gankcopy.view.customview.photoview.PhotoViewAttacher.java

private int getImageViewWidth(ImageView imageView) {
    if (null == imageView)
        return 0;
    return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
}

From source file:com.meiqia.meiqiasdk.third.photoview.PhotoViewAttacher.java

protected int getImageViewWidth(ImageView imageView) {
    if (null == imageView)
        return 0;
    return imageView.getWidth() - imageView.getPaddingLeft() - imageView.getPaddingRight();
}

From source file:com.ndn.menurandom.ImageDownloader.java

private void makeFrameLayout(ImageView imageView) {
    boolean isExist = false;
    ViewGroup vg = (ViewGroup) imageView.getParent();
    if (vg instanceof FrameLayout) {
        FrameLayout frameLayout = (FrameLayout) vg;
        String tag = (String) frameLayout.getTag();
        if (tag != null && tag.equals("fl_imagedownloader")) {
            isExist = true;/*from ww  w.j  a v a  2 s. co m*/
        }
    }

    if (!isExist) {
        int childCount = vg.getChildCount();
        int index = 0;
        while (index < childCount) {
            if (imageView == vg.getChildAt(index)) {
                break;
            }
            index++;
        }
        vg.removeViewAt(index);

        FrameLayout frameLayout = new FrameLayout(vg.getContext().getApplicationContext());
        frameLayout.setTag("fl_imagedownloader");
        ViewGroup.LayoutParams lpImageView = (ViewGroup.LayoutParams) imageView.getLayoutParams();
        frameLayout.setLayoutParams(lpImageView);
        imageView.setLayoutParams(new LayoutParams(lpImageView.width, lpImageView.height));
        frameLayout.setPadding(imageView.getPaddingLeft(), imageView.getPaddingTop(),
                imageView.getPaddingRight(), imageView.getPaddingBottom());
        imageView.setPadding(0, 0, 0, 0);
        frameLayout.addView(imageView);
        vg.addView(frameLayout, index);

        ProgressBar progressBar = new ProgressBar(frameLayout.getContext());
        progressBar.setTag("pb_imagedownloader");
        int leftRightPadding = (imageView.getLayoutParams().width - 50) / 2;
        int topBottomPadding = (imageView.getLayoutParams().height - 50) / 2;
        progressBar.setPadding(leftRightPadding, topBottomPadding, leftRightPadding, topBottomPadding);
        frameLayout.addView(progressBar);

    }
}