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.gdgdevfest.android.apps.devfestbcn.ui.tablet.MapMultiPaneActivity.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    boolean landscape = (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE);

    LinearLayout spacerView = (LinearLayout) findViewById(R.id.map_detail_spacer);
    spacerView.setOrientation(landscape ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL);
    spacerView.setGravity(landscape ? Gravity.END : Gravity.BOTTOM);

    View popupView = findViewById(R.id.map_detail_popup);
    LinearLayout.LayoutParams popupLayoutParams = (LinearLayout.LayoutParams) popupView.getLayoutParams();
    popupLayoutParams.width = landscape ? 0 : ViewGroup.LayoutParams.MATCH_PARENT;
    popupLayoutParams.height = landscape ? ViewGroup.LayoutParams.MATCH_PARENT : 0;
    popupView.setLayoutParams(popupLayoutParams);

    popupView.requestLayout();/*www.ja  v a2 s .  c  o  m*/

    updateMapPadding();
}

From source file:com.gome.haoyuangong.views.MyViewPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;/*from  ww  w  .j a  va 2s. c  om*/
    tabView.setTag("tavView");
    tabView.setId(index);
    //      tabView.setFocusable(true);
    //      tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    //tabView.setPadding(pointSize, 0, pointSize, 0);
    tabView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tabView.setMaxLines(1);
    tabView.setGravity(Gravity.CENTER);
    XmlPullParser xrp = getResources().getXml(R.drawable.tab_button);
    try {
        ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);
        tabView.setTextColor(csl);
    } catch (Exception e) {

    }

    if (iconResId != 0) {
        //tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }

    FrameLayout.LayoutParams tabTvL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabView.setLayoutParams(tabTvL);

    //measureView(tabView);

    LinearLayout layoutWraper1 = new LinearLayout(getContext());
    LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1);
    layoutWraper1.setLayoutParams(lp1);
    layoutWraper1.setGravity(Gravity.CENTER);
    layoutWraper1.setFocusable(true);
    layoutWraper1.setOnClickListener(mTabClickListener);
    layoutWraper1.setPadding(0, 0, 0, 0);
    layoutWraper1.setBackgroundResource(R.drawable.tab_btn_red);

    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setTag("framelayout");
    //      FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(tabView.getMeasuredWidth() + padding, tabView.getMeasuredHeight()+ (int)(padding * 1.5));
    FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    //      frameLayout.setPadding(padding, padding, padding, padding);
    frameLayout.setLayoutParams(fl2);
    //      frameLayout.addView(tabView);

    View hasNew = new View(getContext());
    FrameLayout.LayoutParams hasNewL = new FrameLayout.LayoutParams(pointSize, pointSize);
    hasNew.setLayoutParams(hasNewL);
    hasNewL.gravity = Gravity.TOP | Gravity.RIGHT;
    hasNew.setBackgroundResource(R.drawable.shape_circle);

    FrameLayout tabTvframe = new FrameLayout(getContext());
    FrameLayout.LayoutParams tabTvframeL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabTvframeL.gravity = Gravity.CENTER;
    tabTvframe.setLayoutParams(tabTvframeL);
    tabTvframe.addView(tabView);
    tabTvframe.addView(hasNew);
    hasNew.setVisibility(View.GONE);

    frameLayout.addView(tabTvframe);

    layoutWraper1.addView(frameLayout);

    tabView.setTagView(hasNew);

    mTabLayout.addView(layoutWraper1, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

From source file:com.hippo.nimingban.widget.PostLayout.java

public void hideTypeSend() {
    mHideTypeSendAnimation.cancel();//  w ww . j a va 2  s  . com
    mShowTypeSendAnimation.cancel();

    View typeSendView = getChildAt(1);
    if (typeSendView == null) {
        return;
    }

    LayoutParams lp = (LayoutParams) typeSendView.getLayoutParams();
    lp.hide = true;

    int start = typeSendView.getTop();
    int end = getHeight() - typeSendView.findViewById(R.id.toolbar).getHeight();
    if (start != end) {
        mHideTypeSendAnimation.setIntValues(start, end);
        mHideTypeSendAnimation.start();
    }

    // Add post view bottom margin
    View postView = getChildAt(0);
    if (postView != null) {
        lp = (LayoutParams) postView.getLayoutParams();
        lp.bottomMargin = typeSendView.findViewById(R.id.toolbar).getHeight();
        postView.setLayoutParams(lp);
    }
}

From source file:com.lee.sdk.widget.viewpager.BdPagerTabHost.java

/**
 * tab bar//w w w.  ja va2s.co m
 * 
 * @param height 
 */
public void setTabBarHeight(int height) {
    View container = findViewById(R.id.pager_tab_bar_container);
    if (null != container) {
        ViewGroup.LayoutParams params = container.getLayoutParams();
        if (null != params) {
            params.height = height;
            container.setLayoutParams(params);
            requestLayout();
        }
    }
}

From source file:com.negaheno.ui.Components.PagerSlidingTabStrip.java

private void updateTabStyles() {

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

        View v = tabsContainer.getChildAt(i);

        v.setLayoutParams(defaultTabLayoutParams);
        v.setBackgroundResource(tabBackgroundResId);
        if (shouldExpand) {
            v.setPadding(0, 0, 0, 0);/*from   w  ww .j ava2s. co m*/
            v.setLayoutParams(new LinearLayout.LayoutParams(-1, -1, 1.0F));
        } 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:android.support.wear.widget.CircularProgressLayout.java

public CircularProgressLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mProgressDrawable = new CircularProgressDrawable(context);
    mProgressDrawable.setProgressRotation(DEFAULT_ROTATION);
    mProgressDrawable.setStrokeCap(Paint.Cap.BUTT);
    setBackground(mProgressDrawable);/*w  w w.  j  a v  a 2 s .  co m*/

    // If a child view is added, make it center aligned so it fits in the progress drawable.
    setOnHierarchyChangeListener(new OnHierarchyChangeListener() {
        @Override
        public void onChildViewAdded(View parent, View child) {
            // Ensure that child view is aligned in center
            LayoutParams params = (LayoutParams) child.getLayoutParams();
            params.gravity = Gravity.CENTER;
            child.setLayoutParams(params);
        }

        @Override
        public void onChildViewRemoved(View parent, View child) {

        }
    });

    mController = new CircularProgressLayoutController(this);

    Resources r = context.getResources();
    TypedArray a = r.obtainAttributes(attrs, R.styleable.CircularProgressLayout);

    if (a.getType(R.styleable.CircularProgressLayout_colorSchemeColors) == TypedValue.TYPE_REFERENCE
            || !a.hasValue(R.styleable.CircularProgressLayout_colorSchemeColors)) {
        int arrayResId = a.getResourceId(R.styleable.CircularProgressLayout_colorSchemeColors,
                R.array.circular_progress_layout_color_scheme_colors);
        setColorSchemeColors(getColorListFromResources(r, arrayResId));
    } else {
        setColorSchemeColors(a.getColor(R.styleable.CircularProgressLayout_colorSchemeColors, Color.BLACK));
    }

    setStrokeWidth(a.getDimensionPixelSize(R.styleable.CircularProgressLayout_strokeWidth,
            r.getDimensionPixelSize(R.dimen.circular_progress_layout_stroke_width)));

    setBackgroundColor(a.getColor(R.styleable.CircularProgressLayout_backgroundColor,
            ContextCompat.getColor(context, R.color.circular_progress_layout_background_color)));

    setIndeterminate(a.getBoolean(R.styleable.CircularProgressLayout_indeterminate, false));

    a.recycle();
}

From source file:com.hzx.luoyechat.activity.SettingsFragment.java

private void initSwitchColor() {
    dialog = new android.support.v7.app.AlertDialog.Builder(getActivity()).setAdapter(new BaseAdapter() {
        @Override// www. j ava2s .  c o m
        public int getCount() {
            return colors.length;
        }

        @Override
        public Object getItem(int position) {
            return colors[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = new View(getActivity());
                convertView.setLayoutParams(new AbsListView.LayoutParams(-1, 70));
            }

            convertView.setBackgroundColor(getResources().getColor((Integer) getItem(position)));
            return convertView;
        }
    }, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            //                  Snackbar.make(theme_color, i + ": ", 0).show();
            HXPreferenceUtils.getInstance().setThemeColor(i);
            HXPreferenceUtils.getInstance().setTabIndex(2);
            theme_color.setBackgroundResource(colors[i]);
            getActivity().finish();
            startActivity(new Intent(getActivity(), MainActivity.class));
        }
    });/**/
    rl_switch_theme_color.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.show();
        }
    });
    int colorindex = HXPreferenceUtils.getInstance().getThemeColor();
    theme_color.setBackgroundResource(colors[colorindex]);
}

From source file:com.orange.ocara.ui.activity.EditCommentActivity.java

@Override
void setUpToolbar() {
    super.setUpToolbar();

    final View responseButtonBar = LayoutInflater.from(this)
            .inflate(com.orange.ocara.R.layout.audit_object_toolbar, null);
    responseButtonBar.findViewById(com.orange.ocara.R.id.response_ok_button).setVisibility(View.GONE);

    responseButtonBar.findViewById(com.orange.ocara.R.id.response_nok_button).setVisibility(View.GONE);

    Toolbar.LayoutParams lp = new Toolbar.LayoutParams(Gravity.LEFT);
    responseButtonBar.setLayoutParams(lp);

    toolbar.addView(responseButtonBar);//from w  ww .  j av  a  2s.c o m
}

From source file:com.hadis.mylunbo.carrousel.CircleIndicator.java

private void addIndicator(@DrawableRes int backgroundDrawableId, Animator animator) {
    if (animator.isRunning()) {
        animator.end();/*from   w  ww. ja  v a  2 s  . c  o  m*/
        animator.cancel();
    }

    View Indicator = new View(getContext());
    Indicator.setBackgroundResource(backgroundDrawableId);
    addView(Indicator, mIndicatorWidth, mIndicatorHeight);
    LayoutParams lp = (LayoutParams) Indicator.getLayoutParams();
    lp.leftMargin = mIndicatorMargin;
    lp.rightMargin = mIndicatorMargin;
    Indicator.setLayoutParams(lp);

    animator.setTarget(Indicator);
    animator.start();
}

From source file:com.gqp.duoduo.view.SettlementView.java

private void bindData() {

    viewModel.bindContent(new Action1<Settlement.SettleMessageEntity>() {
        @Override//from w w w  .j ava2 s.  co  m
        public void call(Settlement.SettleMessageEntity deliverModels) {

            settleMessageEntity = deliverModels;
            moneyText.setText("" + settleMessageEntity.getSettelmentTotal().get("goodstotalamount"));

            if (deliverModels != null) {
                mList = deliverModels.getSettelment();
                dataLayout.setVisibility(View.VISIBLE);
                noDataLayout.setVisibility(View.GONE);

                container.removeAllViews();

                LayoutInflater inflater = LayoutInflater.from(getContext());

                View headerView = inflater.inflate(R.layout.common_item_hearder_layout, null);
                ((TextView) headerView.findViewById(R.id.common_item_01)).setText("??");
                ((TextView) headerView.findViewById(R.id.common_item_02)).setText("?");
                headerView.setBackgroundResource(R.color.gray_whiter);
                container.addView(headerView);
                View headdivider = new View(getContext());
                headdivider.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
                headdivider.setBackgroundColor(Color.parseColor("#DDDDDD"));
                container.addView(headdivider);

                int index = 0;
                for (Settlement.MarketSettleEntity marketModel : mList) {

                    View view = inflater.inflate(R.layout.common_item_layout, null);
                    ViewMarketItemHolder holder = new ViewMarketItemHolder(view);
                    holder.bind(marketModel, index);
                    container.addView(view);

                    View divider = new View(getContext());
                    divider.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
                    divider.setBackgroundColor(Color.parseColor("#DDDDDD"));
                    container.addView(divider);
                    index++;
                }
                if (mList != null && mList.size() > 0) {
                    View footerdivider = new View(getContext());
                    footerdivider.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 38));
                    footerdivider.setBackgroundColor(Color.parseColor("#ededed"));
                    container.addView(footerdivider);
                }
                int sIndex = 0;
                List<CommonItem> tmpList = formatData(deliverModels.getSettelmentTotal());
                for (CommonItem commonItem : tmpList) {

                    View view = inflater.inflate(R.layout.common_item_hearder_layout, null);
                    ViewItemHolder holder = new ViewItemHolder(view);
                    holder.bind(commonItem, index);
                    container.addView(view);
                    View divider = new View(getContext());
                    divider.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
                    divider.setBackgroundColor(Color.parseColor("#DDDDDD"));
                    container.addView(divider);
                    if (sIndex == 0) {
                        View footerView01 = new View(getContext());
                        footerView01.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 38));
                        footerView01.setBackgroundResource(R.color.gray_whiter);
                        container.addView(footerView01);
                        View viewitem = inflater.inflate(R.layout.common_item_header_layout, null);
                        ViewItemHeaderHolder holderitem = new ViewItemHeaderHolder(viewitem);
                        holderitem.bind("?", index);
                        container.addView(viewitem);
                        View divider01 = new View(getContext());
                        divider01.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
                        divider01.setBackgroundColor(Color.parseColor("#DDDDDD"));
                        container.addView(divider01);
                    }
                    if (sIndex <= 2) {
                        if (sIndex == 2) {
                            View footerView01 = new View(getContext());
                            footerView01
                                    .setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 38));
                            footerView01.setBackgroundResource(R.color.gray_whiter);
                            container.addView(footerView01);

                        }
                    }
                    if (sIndex > 2 && sIndex <= 6) {
                        if (sIndex == 6) {
                            View footerView01 = new View(getContext());
                            footerView01
                                    .setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 38));
                            footerView01.setBackgroundResource(R.color.gray_whiter);
                            container.addView(footerView01);
                        }
                    }
                    sIndex++;
                }

            } else {
                dataLayout.setVisibility(View.GONE);
                noDataLayout.setVisibility(View.VISIBLE);
                container.setVisibility(View.GONE);
            }

        }
    });

}