Example usage for android.view View setMinimumWidth

List of usage examples for android.view View setMinimumWidth

Introduction

In this page you can find the example usage for android.view View setMinimumWidth.

Prototype

public void setMinimumWidth(int minWidth) 

Source Link

Document

Sets the minimum width of the view.

Usage

From source file:br.com.luizgadao.selfdestruction.views.android.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    //custom width
    int customW = getResources().getDisplayMetrics().widthPixels / mViewPager.getAdapter().getCount();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;/*w  ww.j  a v a2  s  .com*/

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);

            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        //set custom width for tabview
        tabView.setMinimumWidth(customW);

        mTabStrip.addView(tabView);
    }
}

From source file:com.daviancorp.android.ui.general.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;//from   w  w w  . j  a v a  2 s . c o m

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = -2;
            lp.weight = 1;

            tabView.setMinimumWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

From source file:com.ghstudios.android.ui.general.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;// w  w w .  ja v  a 2 s .  co m

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;

            tabView.setMinimumWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

From source file:com.smartsoftasia.sligingtab.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;//from w ww. j a  v a 2 s .c o m

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (navigationMode == NAVIGATION_MODE_TABS) {
            Display display = ((FragmentActivity) getContext()).getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            tabView.setMinimumWidth(size.x / adapter.getCount());
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
    }
}

From source file:com.center.mycode.view.swipelayout.SwipeRevealLayout.java

/**
 * {@inheritDoc}//from  w w  w .  j a  va  2  s  .  c  om
 */
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (getChildCount() < 2) {
        throw new RuntimeException("Layout must have two children");
    }

    final LayoutParams params = getLayoutParams();

    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    final int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
    final int measuredHeight = MeasureSpec.getSize(heightMeasureSpec);

    int desiredWidth = 0;
    int desiredHeight = 0;

    for (int i = 0; i < getChildCount(); i++) {
        final View child = getChildAt(i);
        final LayoutParams childParams = child.getLayoutParams();

        if (childParams != null) {
            if (childParams.height == LayoutParams.MATCH_PARENT) {
                child.setMinimumHeight(measuredHeight);
            }

            if (childParams.width == LayoutParams.MATCH_PARENT) {
                child.setMinimumWidth(measuredWidth);
            }
        }

        measureChild(child, widthMeasureSpec, heightMeasureSpec);
        desiredWidth = Math.max(child.getMeasuredWidth(), desiredWidth);
        desiredHeight = Math.max(child.getMeasuredHeight(), desiredHeight);
    }

    // taking accounts of padding
    desiredWidth += getPaddingLeft() + getPaddingRight();
    desiredHeight += getPaddingTop() + getPaddingBottom();

    // adjust desired width
    if (widthMode == MeasureSpec.EXACTLY) {
        desiredWidth = measuredWidth;
    } else {
        if (params.width == LayoutParams.MATCH_PARENT) {
            desiredWidth = measuredWidth;
        }

        if (widthMode == MeasureSpec.AT_MOST) {
            desiredWidth = (desiredWidth > measuredWidth) ? measuredWidth : desiredWidth;
        }
    }

    // adjust desired height
    if (heightMode == MeasureSpec.EXACTLY) {
        desiredHeight = measuredHeight;
    } else {
        if (params.height == LayoutParams.MATCH_PARENT) {
            desiredHeight = measuredHeight;
        }

        if (heightMode == MeasureSpec.AT_MOST) {
            desiredHeight = (desiredHeight > measuredHeight) ? measuredHeight : desiredHeight;
        }
    }

    setMeasuredDimension(desiredWidth, desiredHeight);
}

From source file:com.yahoo.mobile.itern.guagua.View.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();
    Log.d("GET Count", String.valueOf(adapter.getCount()));
    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;/*from w  ww  .j  a v  a2  s. c  o m*/

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        // Try to scale to screen
        //Display display = mContext.getgetWindowManager().getDefaultDisplay();
        int width = getResources().getDisplayMetrics().widthPixels; // deprecated
        Log.d("Get root view", String.valueOf(width / 2));
        tabView.setMinimumWidth(width / 2);
        mTabStrip.addView(tabView);
    }
}

From source file:org.liberty.android.fantastischmemo.ui.QuizLauncherDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    getDialog().setCanceledOnTouchOutside(true);
    getDialog().setTitle(R.string.quiz_text);
    View v = inflater.inflate(R.layout.quiz_launcher_dialog, container, false);

    startQuizButton = (Button) v.findViewById(R.id.start_quiz_button);

    startQuizButton.setOnClickListener(startQuizButtonOnClickListener);

    quizByGroupRadio = (RadioButton) v.findViewById(R.id.quiz_by_group_radio);

    quizByCategoryRadio = (RadioButton) v.findViewById(R.id.quiz_by_category_radio);

    quizGroupSizeTitle = (TextView) v.findViewById(R.id.quiz_group_size_title);

    quizGroupSizeEdit = (EditText) v.findViewById(R.id.quiz_group_size);
    // Make sure the text value is sanity and update other information
    // about the group size and etc accordingly.
    quizGroupSizeEdit.addTextChangedListener(editTextWatcher);
    quizGroupSizeEdit.setOnFocusChangeListener(sanitizeInputListener);

    quizGroupNumberTitle = (TextView) v.findViewById(R.id.quiz_group_number_title);

    quizGroupNumberEdit = (EditText) v.findViewById(R.id.quiz_group_number);
    quizGroupNumberEdit.addTextChangedListener(editTextWatcher);
    quizGroupNumberEdit.setOnFocusChangeListener(sanitizeInputListener);

    categoryButton = (Button) v.findViewById(R.id.category_button);
    categoryButton.setOnClickListener(categoryButtonListener);

    Rect displayRectangle = new Rect();
    Window window = mActivity.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);

    v.setMinimumWidth((int) (displayRectangle.width() * 0.9f));

    return v;//from  w  w  w.  j a va2s.com
}

From source file:android.support.designox.widget.TabLayout.java

private void updateTabViews(final boolean requestLayout) {
    for (int i = 0; i < mTabStrip.getChildCount(); i++) {
        View child = mTabStrip.getChildAt(i);
        child.setMinimumWidth(getTabMinWidth());
        updateTabViewLayoutParams((LinearLayout.LayoutParams) child.getLayoutParams());
        if (requestLayout) {
            child.requestLayout();/*from   ww w.j  a va2s .co  m*/
        }
    }
}

From source file:com.adherence.adherence.SwipeRevealLayout.java

/**
 * {@inheritDoc}//from   w ww .  j a v  a 2s . c o  m
 */
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (getChildCount() < 2) {
        throw new RuntimeException("Layout must have two children");
    }

    final LayoutParams params = getLayoutParams();

    final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    final int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    int desiredWidth = 0;
    int desiredHeight = 0;

    // first find the largest child
    for (int i = 0; i < getChildCount(); i++) {
        final View child = getChildAt(i);
        measureChild(child, widthMeasureSpec, heightMeasureSpec);
        desiredWidth = Math.max(child.getMeasuredWidth(), desiredWidth);
        desiredHeight = Math.max(child.getMeasuredHeight(), desiredHeight);
    }
    // create new measure spec using the largest child width
    widthMeasureSpec = MeasureSpec.makeMeasureSpec(desiredWidth, widthMode);
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(desiredHeight, heightMode);

    final int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
    final int measuredHeight = MeasureSpec.getSize(heightMeasureSpec);

    for (int i = 0; i < getChildCount(); i++) {
        final View child = getChildAt(i);
        final LayoutParams childParams = child.getLayoutParams();

        if (childParams != null) {
            if (childParams.height == LayoutParams.MATCH_PARENT) {
                child.setMinimumHeight(measuredHeight);
            }

            if (childParams.width == LayoutParams.MATCH_PARENT) {
                child.setMinimumWidth(measuredWidth);
            }
        }

        measureChild(child, widthMeasureSpec, heightMeasureSpec);
        desiredWidth = Math.max(child.getMeasuredWidth(), desiredWidth);
        desiredHeight = Math.max(child.getMeasuredHeight(), desiredHeight);
    }

    // taking accounts of padding
    desiredWidth += getPaddingLeft() + getPaddingRight();
    desiredHeight += getPaddingTop() + getPaddingBottom();

    // adjust desired width
    if (widthMode == MeasureSpec.EXACTLY) {
        desiredWidth = measuredWidth;
    } else {
        if (params.width == LayoutParams.MATCH_PARENT) {
            desiredWidth = measuredWidth;
        }

        if (widthMode == MeasureSpec.AT_MOST) {
            desiredWidth = (desiredWidth > measuredWidth) ? measuredWidth : desiredWidth;
        }
    }

    // adjust desired height
    if (heightMode == MeasureSpec.EXACTLY) {
        desiredHeight = measuredHeight;
    } else {
        if (params.height == LayoutParams.MATCH_PARENT) {
            desiredHeight = measuredHeight;
        }

        if (heightMode == MeasureSpec.AT_MOST) {
            desiredHeight = (desiredHeight > measuredHeight) ? measuredHeight : desiredHeight;
        }
    }

    setMeasuredDimension(desiredWidth, desiredHeight);
}

From source file:android.support.design.widget.RaeTabLayout.java

void updateTabViews(final boolean requestLayout) {
    for (int i = 0; i < mTabStrip.getChildCount(); i++) {
        View child = mTabStrip.getChildAt(i);
        child.setMinimumWidth(getTabMinWidth());
        updateTabViewLayoutParams((LinearLayout.LayoutParams) child.getLayoutParams());
        if (requestLayout) {
            child.requestLayout();/*from w w w. j a  v  a2  s.c o  m*/
        }
    }
}