Example usage for android.view View setLayoutParams

List of usage examples for android.view View setLayoutParams

Introduction

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

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.charon.materialsample.view.ScrollingTabs.java

/**
 * Add tab view.//w w  w  .  j a  v a2  s  . c o m
 */
private void initTabView() {
    int totalWidth = 0;

    if (mViewPager != null && mTabAdapter != null) {
        mContainer.removeAllViews();

        if (mEqualWidth) {
            for (int i = 0; i < mViewPager.getAdapter().getCount(); i++) {
                View tab = mTabAdapter.getView(i);
                measureView(tab);
                totalWidth += tab.getWidth();

                if (tab.getLayoutParams() != null) {
                    // int width = tab.getLayoutParams().width;
                    // int height = tab.getLayoutParams().height;
                } else {
                    tab.setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 100f));
                }

                if (mTabAdapter.getSeparator() != null && i != mViewPager.getAdapter().getCount() - 1) {
                    isUseSeperator = true;
                    measureView(mTabAdapter.getSeparator());
                    totalWidth += mTabAdapter.getSeparator().getWidth();
                }
            }

            if (totalWidth < mWindowWidth) {
                int count = mViewPager.getAdapter().getCount();
                if (isUseSeperator) {
                    tabWidth = (mWindowWidth - (count - 1) * mTabAdapter.getSeparator().getWidth()) / count;
                } else {
                    tabWidth = mWindowWidth / count;
                }
            }
        }

        for (int i = 0; i < mViewPager.getAdapter().getCount(); i++) {
            final View tab = mTabAdapter.getView(i);
            tab.setTag(i);

            if (tabWidth != 0) {
                mContainer.addView(tab,
                        new LinearLayout.LayoutParams(tabWidth, LinearLayout.LayoutParams.MATCH_PARENT));
            } else {
                mContainer.addView(tab,
                        new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 100f));
            }

            // Segmentation view
            if (mTabAdapter.getSeparator() != null && i != mViewPager.getAdapter().getCount() - 1) {
                isUseSeperator = true;
                mContainer.addView(mTabAdapter.getSeparator());
            }

            // Set click listener on tab.
            tab.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    int index = (Integer) tab.getTag();
                    if (mTabClickListener != null) {
                        mTabClickListener.onClick(index);
                    } else {
                        if (mViewPager.getCurrentItem() == index) {
                            selectTab(index);
                        } else {
                            // If ViewPager change the page, the listener
                            // will call selectTab method
                            mViewPager.setCurrentItem(index, true);
                        }
                    }
                }
            });

        }

        // Set the current selected tab when first coming.
        selectTab(mViewPager.getCurrentItem());
    }
}

From source file:com.charon.scrollingtabs.view.ScrollingTabs.java

/**
 * Add tab view.//from w w  w . j  av a  2 s. c  o  m
 */
private void initTabView() {
    int totalWidth = 0;

    if (mViewPager != null && mTabAdapter != null) {
        mContainer.removeAllViews();

        if (mEqualWidth) {
            for (int i = 0; i < mViewPager.getAdapter().getCount(); i++) {
                View tab = mTabAdapter.getView(i);
                measureView(tab);
                totalWidth += tab.getWidth();

                if (tab.getLayoutParams() != null) {
                    // int width = tab.getLayoutParams().width;
                    // int height = tab.getLayoutParams().height;
                } else {
                    tab.setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 100f));
                }

                if (mTabAdapter.getSeparator() != null && i != mViewPager.getAdapter().getCount() - 1) {
                    isUseSeperator = true;
                    measureView(mTabAdapter.getSeparator());
                    totalWidth += mTabAdapter.getSeparator().getWidth();
                }
            }

            if (totalWidth < mWindowWidth) {
                int count = mViewPager.getAdapter().getCount();
                if (isUseSeperator) {
                    tabWidth = (mWindowWidth - (count - 1) * mTabAdapter.getSeparator().getWidth()) / count;
                } else {
                    tabWidth = mWindowWidth / count;
                }
            }
        }

        for (int i = 0; i < mViewPager.getAdapter().getCount(); i++) {
            final View tab = mTabAdapter.getView(i);
            tab.setTag(i);

            if (tabWidth != 0) {
                mContainer.addView(tab, new LinearLayout.LayoutParams(tabWidth,
                        android.widget.LinearLayout.LayoutParams.MATCH_PARENT));
            } else {
                mContainer.addView(tab,
                        new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 100f));
            }

            // Segmentation view
            if (mTabAdapter.getSeparator() != null && i != mViewPager.getAdapter().getCount() - 1) {
                isUseSeperator = true;
                mContainer.addView(mTabAdapter.getSeparator());
            }

            // Set click listener on tab.
            tab.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    int index = (Integer) tab.getTag();
                    if (mTabClickListener != null) {
                        mTabClickListener.onClick(index);
                    } else {
                        if (mViewPager.getCurrentItem() == index) {
                            selectTab(index);
                        } else {
                            // If ViewPager change the page, the listener
                            // will call selectTab method
                            mViewPager.setCurrentItem(index, true);
                        }
                    }
                }
            });

        }

        // Set the current selected tab when first coming.
        selectTab(mViewPager.getCurrentItem());
    }
}

From source file:com.messi.cantonese.study.views.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);
        /**4???**/
        v.setLayoutParams(defaultTabLayoutParams);
        //         v.setLayoutParams(expandedTabLayoutParams);
        v.setBackgroundResource(tabBackgroundResId);
        if (shouldExpand) {
            v.setPadding(0, 0, 0, 0);/* w  w w .j  av a2  s .c  om*/
        } else {
            v.setPadding(tabPadding, 0, tabPadding, 0);
        }

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        }
    }

}

From source file:com.insalyon.les24heures.JazzyViewPager.JazzyViewPager.java

private View wrapChild(View child) {
    if (!mOutlineEnabled || child instanceof OutlineContainer)
        return child;
    OutlineContainer out = new OutlineContainer(getContext());
    out.setLayoutParams(generateDefaultLayoutParams());
    child.setLayoutParams(
            new OutlineContainer.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    out.addView(child);// w  w  w. jav  a2 s.  c  om
    return out;
}

From source file:com.aizou.core.widget.pagerIndicator.indicator.FixedIndicatorView.java

/**
 * tab??//from   w w  w. j a  va  2 s.  c  o  m
 */
private void measureTabs() {
    int count = getChildCount();
    switch (splitMethod) {
    case SPLITMETHOD_EQUALS:
        for (int i = 0; i < count; i++) {
            View view = getChildAt(i);
            LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
            layoutParams.width = 0;
            layoutParams.weight = 1;
            view.setLayoutParams(layoutParams);
        }
        break;
    case SPLITMETHOD_WRAP:
        for (int i = 0; i < count; i++) {
            View view = getChildAt(i);
            LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
            layoutParams.width = LayoutParams.WRAP_CONTENT;
            layoutParams.weight = 0;
            view.setLayoutParams(layoutParams);
        }
        break;
    case SPLITMETHOD_WEIGHT:
        for (int i = 0; i < count; i++) {
            View view = getChildAt(i);
            LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
            layoutParams.width = LayoutParams.WRAP_CONTENT;
            layoutParams.weight = 1;
            view.setLayoutParams(layoutParams);
        }
        break;
    }
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterListView.java

/**
 * Create shadow wrapper with a sticky view  at given position
 *///from   w  w w  .j  av  a 2s . c  o  m
void createStickyShadow(int position) {

    // recycle shadow
    StickyWrapper stickyViewShadow = recycledHeaderView;
    recycledHeaderView = null;

    // create new shadow, if needed
    if (stickyViewShadow == null) {
        stickyViewShadow = new StickyWrapper();
    }
    // request new view using recycled view, if such
    View stickyView = getAdapter().getView(position, stickyViewShadow.view, MessageCenterListView.this);

    // read layout parameters
    LayoutParams layoutParams = (LayoutParams) stickyView.getLayoutParams();
    if (layoutParams == null) {
        layoutParams = (LayoutParams) generateDefaultLayoutParams();
        stickyView.setLayoutParams(layoutParams);
    }

    View childLayout = ((ViewGroup) stickyView).getChildAt(0);
    int heightMode = MeasureSpec.getMode(layoutParams.height);
    int heightSize = MeasureSpec.getSize(layoutParams.height);

    if (heightMode == MeasureSpec.UNSPECIFIED) {
        heightMode = MeasureSpec.EXACTLY;
    }

    int maxHeight = getHeight() - getListPaddingTop() - getListPaddingBottom();
    if (heightSize > maxHeight) {
        heightSize = maxHeight;
    }
    // assuming left and right additional paddings are the same
    int ws = MeasureSpec.makeMeasureSpec(getWidth() - getListPaddingLeft() - getListPaddingRight(),
            MeasureSpec.EXACTLY);
    int hs = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
    stickyView.measure(ws, hs);
    stickyView.layout(0, 0, stickyView.getMeasuredWidth(), stickyView.getMeasuredHeight());

    // initialize shadow
    stickyViewShadow.view = stickyView;
    stickyViewShadow.position = position;
    stickyViewShadow.id = getAdapter().getItemId(position);
    stickyViewShadow.additionalIndent = childLayout.getPaddingLeft();

    stickyWrapper = stickyViewShadow;
}

From source file:com.github.nitrico.mapviewpager.MapViewPager.java

private void setWeights() {
    // viewPager/*from   w  ww  .  ja va  2s  .  c o  m*/
    LinearLayout.LayoutParams pagerParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT, mapWeight);
    viewPager.setLayoutParams(pagerParams);
    // mapFragment
    View mapView = mapFragment.getView();
    if (mapView != null) {
        LinearLayout.LayoutParams mapParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT, pagerWeight);
        mapView.setLayoutParams(mapParams);
    }
}

From source file:com.nttec.everychan.ui.tabs.TabsAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView == null ? inflater.inflate(R.layout.sidebar_tabitem, parent, false) : convertView;
    View dragHandler = view.findViewById(R.id.tab_drag_handle);
    ImageView favIcon = (ImageView) view.findViewById(R.id.tab_favicon);
    TextView title = (TextView) view.findViewById(R.id.tab_text_view);
    ImageView closeBtn = (ImageView) view.findViewById(R.id.tab_close_button);

    dragHandler.getLayoutParams().width = position == draggingItem ? ViewGroup.LayoutParams.WRAP_CONTENT : 0;
    dragHandler.setLayoutParams(dragHandler.getLayoutParams());

    if (position == selectedItem) {
        TypedValue typedValue = ThemeUtils.resolveAttribute(context.getTheme(), R.attr.sidebarSelectedItem,
                true);/*w  ww.j a  v  a 2s  .  c  om*/
        if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT
                && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
            view.setBackgroundColor(typedValue.data);
        } else {
            view.setBackgroundResource(typedValue.resourceId);
        }
    } else {
        view.setBackgroundColor(Color.TRANSPARENT);
    }

    TabModel model = this.getItem(position);

    switch (model.type) {
    case TabModel.TYPE_NORMAL:
    case TabModel.TYPE_LOCAL:
        closeBtn.setVisibility(View.VISIBLE);
        String titleText = model.title;
        if (model.unreadPostsCount > 0 || model.autoupdateError) {
            StringBuilder titleStringBuilder = new StringBuilder();
            if (model.unreadSubscriptions)
                titleStringBuilder.append("[*] ");
            if (model.autoupdateError)
                titleStringBuilder.append("[X] ");
            if (model.unreadPostsCount > 0)
                titleStringBuilder.append('[').append(model.unreadPostsCount).append("] ");
            titleText = titleStringBuilder.append(titleText).toString();
        }
        title.setText(titleText);
        ChanModule chan = MainApplication.getInstance().getChanModule(model.pageModel.chanName);
        Drawable icon = chan != null ? chan.getChanFavicon()
                : ResourcesCompat.getDrawable(context.getResources(), android.R.drawable.ic_delete, null);
        if (icon != null) {
            if (model.type == TabModel.TYPE_LOCAL) {
                Drawable[] layers = new Drawable[] { icon, ResourcesCompat.getDrawable(context.getResources(),
                        R.drawable.favicon_overlay_local, null) };
                icon = new LayerDrawable(layers);
            }
            /* XXX
             ?       ( overlay  favicon    ),
             ?   ?? ,   ,     (   ).
            ?    ? ? , , ? -? -  ,    ?.
               ??  ?,   ? ?  .
                    
            else if (model.type == TabModel.TYPE_NORMAL && model.pageModel != null &&
                    model.pageModel.type == UrlPageModel.TYPE_THREADPAGE && model.autoupdateBackground &&
                    MainApplication.getInstance().settings.isAutoupdateEnabled() &&
                    MainApplication.getInstance().settings.isAutoupdateBackground()) {
                Drawable[] layers = new Drawable[] {
                        icon, ResourcesCompat.getDrawable(context.getResources(), R.drawable.favicon_overlay_autoupdate, null) };
                icon = new LayerDrawable(layers);
            }
            */
            favIcon.setImageDrawable(icon);
            favIcon.setVisibility(View.VISIBLE);
        } else {
            favIcon.setVisibility(View.GONE);
        }
        break;
    default:
        closeBtn.setVisibility(View.GONE);
        title.setText(R.string.error_deserialization);
        favIcon.setVisibility(View.GONE);
    }

    closeBtn.setTag(position);
    closeBtn.setOnClickListener(onCloseClick);
    return view;
}

From source file:com.granita.tasks.groupings.BaseTaskViewDescriptor.java

@SuppressLint("NewApi")
protected void resetFlingView(View view) {
    View flingContentView = getView(view, getFlingContentViewId());
    if (flingContentView == null) {
        flingContentView = view;/*from ww w .j av a 2s  . co  m*/
    }

    if (android.os.Build.VERSION.SDK_INT >= 14) {
        if (flingContentView.getTranslationX() != 0) {
            flingContentView.setTranslationX(0);
            flingContentView.setAlpha(1);
        }
    } else {
        LayoutParams layoutParams = (LayoutParams) flingContentView.getLayoutParams();
        if (layoutParams.leftMargin != 0 || layoutParams.rightMargin != 0) {
            layoutParams.setMargins(0, layoutParams.topMargin, 0, layoutParams.bottomMargin);
            flingContentView.setLayoutParams(layoutParams);
        }
    }
}

From source file:com.lgh.tool.myview.PagerSlidingTabStrip.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (allowWidthFull && tabsLayout != null) {
        View childView;
        for (int w = 0, size = tabsLayout.getChildCount(); w < size; w++) {
            childView = tabsLayout.getChildAt(w);
            ViewGroup.LayoutParams params = childView.getLayoutParams();
            params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            childView.setLayoutParams(params);
        }/*from   w  w  w .  j av a2  s .c  o m*/
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    if (!allowWidthFull) {
        return;
    }
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout == null) {
        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);
}