Example usage for android.view ViewGroup getMeasuredWidth

List of usage examples for android.view ViewGroup getMeasuredWidth

Introduction

In this page you can find the example usage for android.view ViewGroup getMeasuredWidth.

Prototype

public final int getMeasuredWidth() 

Source Link

Document

Like #getMeasuredWidthAndState() , but only returns the raw width component (that is the result is masked by #MEASURED_SIZE_MASK ).

Usage

From source file:com.taobao.luaview.view.adapter.LVPagerAdapter.java

/**
 * layout params??view?// w  w w  . j  av a 2  s .c  o  m
 *
 * @param container
 * @return
 */
private RelativeLayout.LayoutParams createLayoutParams(ViewGroup container) {
    final RelativeLayout.LayoutParams layoutParams = LuaViewUtil.createRelativeLayoutParamsWM();
    if (container != null) {
        layoutParams.width = container.getMeasuredWidth();
        layoutParams.height = container.getMeasuredHeight();
    }
    return layoutParams;
}

From source file:com.aibasis.parent.widget.PagerSlidingTabStrip.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    if (!allowWidthFull)
        return;//from   ww  w. j  ava 2  s.c o m
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout == null || tabsLayout.getMeasuredWidth() >= getMeasuredWidth())
        return;
    if (tabsLayout.getChildCount() <= 0)
        return;

    if (tabViews == null) {
        tabViews = new ArrayList<View>();
    } else {
        tabViews.clear();
    }
    for (int w = 0; w < tabsLayout.getChildCount(); w++) {
        tabViews.add(tabsLayout.getChildAt(w));
    }

    adjustChildWidthWithParent(tabViews,
            getMeasuredWidth() - tabsLayout.getPaddingLeft() - tabsLayout.getPaddingRight(), widthMeasureSpec,
            heightMeasureSpec);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:com.manuelpeinado.imagelayout.ImageLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int widthSpec = MeasureSpec.getSize(widthMeasureSpec);
    int width = widthSpec;
    int heightSpec = MeasureSpec.getSize(heightMeasureSpec);
    int height = heightSpec;
    boolean isExactWidth = widthMode == MeasureSpec.EXACTLY;
    boolean isExactHeight = heightMode == MeasureSpec.EXACTLY;
    int imageWidth = image == null ? 1 : image.getWidth();
    int imageHeight = image == null ? 1 : image.getHeight();
    float imageAspectRatio = (imageWidth + getPaddingLeft() + getPaddingRight())
            / ((float) imageHeight + getPaddingTop() + getPaddingBottom());
    if (isExactWidth && !isExactHeight) {
        height = (int) (width / imageAspectRatio);
        if (heightMode == MeasureSpec.AT_MOST && height > heightSpec) {
            height = heightSpec;//from   ww w  .  j a v a  2 s  . c  o m
        }
    } else if (isExactHeight && !isExactWidth) {
        ViewGroup parent = (ViewGroup) getParent();
        int parentWidth = parent.getMeasuredWidth();
        switch (getLayoutParams().width) {
        case ViewGroup.LayoutParams.MATCH_PARENT:
            width = parentWidth;
            break;
        default:
            // If we have WRAP_CONTENT we want to make the width at least the available
            // space in the parent so it will appear centered (it could be more to keep the aspect ratio).
            // This is a workaround for this view being inside HorizontalScrollView (because it cannot be
            // centered there).
            width = Math.max(parentWidth, (int) (height * imageAspectRatio));
            break;
        }

        if (widthMode == MeasureSpec.AT_MOST && width > widthSpec) {
            width = widthSpec;
        }
    }

    setMeasuredDimension(width, height);

    int effectiveWidth = width - getPaddingLeft() - getPaddingRight();
    int effectiveHeight = height - getPaddingTop() - getPaddingBottom();
    destRect = fitter.fit(image, effectiveWidth, effectiveHeight);
    adjustDestRectForPadding();

    int N = getChildCount();
    for (int i = 0; i < N; ++i) {
        View child = getChildAt(i);
        measureChild(child);
    }
}

From source file:com.cicada.startup.common.ui.view.indicator.ViewPagerIndicator.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    if (!allowWidthFull) {
        return;//from   w ww  .  j a v a 2s.c o  m
    }
    setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight() + slidingBlockHeight);
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout == null || tabsLayout.getMeasuredWidth() >= getMeasuredWidth())
        return;
    if (tabsLayout.getChildCount() <= 0)
        return;

    if (tabViews == null) {
        tabViews = new ArrayList<View>();
    } else {
        tabViews.clear();
    }
    for (int w = 0; w < tabsLayout.getChildCount(); w++) {
        tabViews.add(tabsLayout.getChildAt(w));
    }

    adjustChildWidthWithParent(tabViews,
            getMeasuredWidth() - tabsLayout.getPaddingLeft() - tabsLayout.getPaddingRight(), widthMeasureSpec,
            heightMeasureSpec);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:com.mfh.litecashier.ui.widget.TopSlidingTabStrip.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    if (!allowWidthFull)
        return;//from   w  ww . j ava2 s . c o m
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout == null || tabsLayout.getMeasuredWidth() >= getMeasuredWidth())
        return;
    if (tabsLayout.getChildCount() <= 0)
        return;

    if (tabViews == null) {
        tabViews = new ArrayList<>();
    } else {
        tabViews.clear();
    }
    for (int w = 0; w < tabsLayout.getChildCount(); w++) {
        tabViews.add(tabsLayout.getChildAt(w));
    }

    adjustChildWidthWithParent(tabViews,
            getMeasuredWidth() - tabsLayout.getPaddingLeft() - tabsLayout.getPaddingRight(), widthMeasureSpec,
            heightMeasureSpec);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:com.mfh.framework.uikit.widget.SideSlidingTabStrip.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    if (!allowWidthFull)
        return;/*from   w w  w  .j a v  a 2  s.c o m*/
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout == null || tabsLayout.getMeasuredWidth() >= getMeasuredWidth())
        return;
    if (tabsLayout.getChildCount() <= 0)
        return;

    if (tabViews == null) {
        tabViews = new ArrayList<>();
    } else {
        tabViews.clear();
    }
    for (int w = 0; w < tabsLayout.getChildCount(); w++) {
        tabViews.add(tabsLayout.getChildAt(w));
    }

    adjustChildHeightWithParent(tabViews,
            getMeasuredHeight() - tabsLayout.getPaddingTop() - tabsLayout.getPaddingBottom(), widthMeasureSpec,
            heightMeasureSpec);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:io.v.android.apps.syncslides.NavigateFragment.java

private void setThumbNull(ImageView thumb) {
    thumb.setImageDrawable(null);//from   www . j  a v  a2  s. co  m
    // In landscape, the height is dependent on the image size.  Because we don't have an
    // image, assume all of the images are 16:9.  The width is fixed, so we can calculate
    // the expected height.
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        ViewGroup grandparent = (ViewGroup) thumb.getParent().getParent();
        ViewGroup.LayoutParams thumbParams = thumb.getLayoutParams();
        thumbParams.height = (int) ((9 / 16.0) * grandparent.getMeasuredWidth());
    }
}

From source file:audio.lisn.adapter.StoreBookViewAdapter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_store_book, parent, false);
    view.setMinimumWidth(parent.getMeasuredWidth());

    view.setOnClickListener(new View.OnClickListener() {
        @Override// w  w  w .  j  a  v a2 s .c  o m
        public void onClick(final View v) {
            releaseMediaPlayer();

            if (listener != null) {

                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {

                        listener.onStoreBookSelect(v, (AudioBook) v.getTag(),
                                AudioBook.SelectedAction.ACTION_DETAIL);
                    }
                }, 200);
            }
        }
    });

    return new ViewHolder(view);
}

From source file:com.jun.fakeoschina.widget.PagerSlidingTabStrip.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    if (!allowWidthFull)
        return;/* w w w .  j a  va2s  .  c  om*/
    ViewGroup tabsLayout = getTabsLayout();
    // tabsLayout.getMeasuredWidth() ? 528
    // getMeasuredWidth() pagerSlidingTabStrip xml720 android:layout_width="match_parent"
    if (tabsLayout == null || tabsLayout.getMeasuredWidth() >= getMeasuredWidth())
        return;
    if (tabsLayout.getChildCount() <= 0)
        return;

    if (tabViews == null) {
        tabViews = new ArrayList<View>();
    } else {
        tabViews.clear();
    }
    for (int w = 0; w < tabsLayout.getChildCount(); w++) {
        tabViews.add(tabsLayout.getChildAt(w));
    }

    adjustChildWidthWithParent(tabViews,
            getMeasuredWidth() - tabsLayout.getPaddingLeft() - tabsLayout.getPaddingRight(), widthMeasureSpec,
            heightMeasureSpec);

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:com.waz.zclient.pages.main.participants.dialog.ParticipantsDialogFragment.java

private void adjustAccordingToAnchor() {
    Bundle bundle = getArguments();/*from   w  w  w  .  j av a  2 s  .  c o m*/
    if (bundle == null || getView() == null) {
        return;
    }
    View view = getView();
    ViewGroup viewGroup = (ViewGroup) view.getParent();
    Rect rect = bundle.getParcelable(ARG_ANCHOR_RECT);
    int posX = bundle.getInt(ARG_POS_X);
    int posY = bundle.getInt(ARG_POS_Y);

    final int widthSpec = View.MeasureSpec.makeMeasureSpec(
            viewGroup.getMeasuredWidth() - viewGroup.getPaddingLeft() - viewGroup.getPaddingRight(),
            View.MeasureSpec.AT_MOST);
    final int heightSpec = View.MeasureSpec.makeMeasureSpec(
            viewGroup.getMeasuredHeight() - viewGroup.getPaddingTop() - viewGroup.getPaddingBottom(),
            View.MeasureSpec.AT_MOST);
    view.measure(widthSpec, heightSpec);

    ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) dialogFrameLayout
            .getLayoutParams();
    int rootHeight = dialogFrameLayout.getMeasuredHeight();
    int rootWidth = dialogFrameLayout.getMeasuredWidth();

    int dialogHeight = rootHeight + layoutParams.bottomMargin + layoutParams.topMargin;
    int dialogWidth = rootWidth + layoutParams.leftMargin + layoutParams.rightMargin;

    setDialogPosition(rect, posX, posY, dialogWidth, dialogHeight);
}