Java Code Examples for android.widget.RelativeLayout#LayoutParams

The following examples show how to use android.widget.RelativeLayout#LayoutParams . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultHeaderTransformer.java    From Klyph with MIT License 6 votes vote down vote up
private void applyProgressBarStyle() {
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, mProgressBarHeight);

    switch (mProgressBarStyle) {
        case PROGRESS_BAR_STYLE_INSIDE:
            lp.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.ptr_content);
            break;
        case PROGRESS_BAR_STYLE_OUTSIDE:
            lp.addRule(RelativeLayout.BELOW, R.id.ptr_content);
            break;
    }

    if (mHeaderProgressBar != null)
    	mHeaderProgressBar.setLayoutParams(lp);
}
 
Example 2
Source File: OnSwipeTouchListener.java    From evercam-android with GNU Affero General Public License v3.0 6 votes vote down vote up
private void onActionZoom(View view) {
    int originalWidth = view.getWidth();
    int originalHeight = view.getHeight();

    long currentTime = System.nanoTime();
    if (time != 0 && (currentTime - time) > 10000000) {
        int leftOffset = (int) (originalWidth - (originalWidth * scaleListener.scaleFactor));
        int topOffset = (int) (originalHeight - (originalHeight * scaleListener.scaleFactor));
        Log.e(TAG, "Offset: " + leftOffset + "," + topOffset);

        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
        layoutParams.setMargins(leftOffset, topOffset, leftOffset, topOffset);
        view.setLayoutParams(layoutParams);

        //Avoid showing the blanks
        if (view.getX() >= 0) {
            view.setX(0);
        }
        if (view.getX() + view.getWidth() <= getScreenWidth()) {
            view.setX(getScreenWidth() - view.getWidth());
        }
    }

    time = System.nanoTime();
}
 
Example 3
Source File: EditPage.java    From Mobike with Apache License 2.0 5 votes vote down vote up
/** 动态适配编辑界面的高度 */
public void run() {
	int height = svContent.getChildAt(0).getHeight();
	RelativeLayout.LayoutParams lp = R.forceCast(svContent.getLayoutParams());
	if (height > maxBodyHeight && lp.height != maxBodyHeight) {
		lp.height = maxBodyHeight;
		svContent.setLayoutParams(lp);
	} else if (height < maxBodyHeight && lp.height == maxBodyHeight) {
		lp.height = LayoutParams.WRAP_CONTENT;
		svContent.setLayoutParams(lp);
	}
}
 
Example 4
Source File: ExpansionPanelSampleActivityProgrammatically.java    From ExpansionPanel with Apache License 2.0 5 votes vote down vote up
@NonNull
private ExpansionHeader createExpansionHeader() {
    final ExpansionHeader expansionHeader = new ExpansionHeader(this);
    expansionHeader.setBackgroundColor(Color.WHITE);

    expansionHeader.setPadding(dpToPx(this, 16), dpToPx(this, 8), dpToPx(this, 16), dpToPx(this, 8));

    final RelativeLayout layout = new RelativeLayout(this);
    expansionHeader.addView(layout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); //equivalent to addView(linearLayout)

    //image
    final ImageView expansionIndicator = new AppCompatImageView(this);
    expansionIndicator.setImageResource(R.drawable.ic_expansion_header_indicator_grey_24dp);
    final RelativeLayout.LayoutParams imageLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    imageLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    imageLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
    layout.addView(expansionIndicator, imageLayoutParams);

    //label
    final TextView text = new TextView(this);
    text.setText("Trip name");
    text.setTextColor(Color.parseColor("#3E3E3E"));

    final RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    textLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    textLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL);

    layout.addView(text, textLayoutParams);

    expansionHeader.setExpansionHeaderIndicator(expansionIndicator);
    return expansionHeader;
}
 
Example 5
Source File: BlockListView.java    From cube-sdk with Apache License 2.0 5 votes vote down vote up
public void onDataListChange() {

        removeAllViews();

        int len = mBlockListAdapter.getCount();
        int w = mBlockListAdapter.getBlockWidth();
        int h = mBlockListAdapter.getBlockHeight();
        int columnNum = mBlockListAdapter.getCloumnNum();

        int horizontalSpacing = mBlockListAdapter.getHorizontalSpacing();
        int verticalSpacing = mBlockListAdapter.getVerticalSpacing();

        boolean blockDescendant = getDescendantFocusability() == ViewGroup.FOCUS_BLOCK_DESCENDANTS;

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

            RelativeLayout.LayoutParams lyp = new RelativeLayout.LayoutParams(w, h);
            int row = i / columnNum;
            int clo = i % columnNum;
            int left = 0;
            int top = 0;

            if (clo > 0) {
                left = (horizontalSpacing + w) * clo;
            }
            if (row > 0) {
                top = (verticalSpacing + h) * row;
            }
            lyp.setMargins(left, top, 0, 0);
            View view = mBlockListAdapter.getView(mLayoutInflater, i);
            if (!blockDescendant) {
                view.setOnClickListener(mOnClickListener);
            }
            view.setTag(INDEX_TAG, i);
            addView(view, lyp);
        }
        requestLayout();
    }
 
Example 6
Source File: BaseMessageDialog.java    From Leanplum-Android-SDK with Apache License 2.0 5 votes vote down vote up
private TextView createMessageView(Context context) {
  TextView view = new TextView(context);
  RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
      LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  view.setLayoutParams(layoutParams);
  view.setGravity(Gravity.CENTER);
  view.setText(options.getMessageText());
  view.setTextColor(options.getMessageColor());
  view.setTextSize(TypedValue.COMPLEX_UNIT_SP, SizeUtil.textSize0_1);
  return view;
}
 
Example 7
Source File: CastDetails.java    From moviedb-android with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the icons position when called.
 */
public void updateIconDownPos() {
    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(homeIcon.getWidth(), homeIcon.getHeight());
    RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(galleryIcon.getWidth(), galleryIcon.getHeight());
    lp1.addRule(RelativeLayout.ALIGN_PARENT_END);
    lp3.addRule(RelativeLayout.ALIGN_PARENT_END);

    lp1.setMargins(0, (int) (scale * (506 + iconMarginConstant - iconMarginLandscape + iconConstantSpecialCase) + 0.5f), (int) (scale * 23 + 0.5f), 0);
    homeIcon.setLayoutParams(lp1);
    lp3.setMargins(0, (int) (scale * (506 + iconMarginConstant - iconMarginLandscape + iconConstantSpecialCase) + 0.5f), (int) (scale * 23 + 0.5f), 0);
    galleryIcon.setLayoutParams(lp3);
}
 
Example 8
Source File: AmountView.java    From px-android with MIT License 5 votes vote down vote up
private void configureViewsVisibilityDefault() {
    amountBeforeDiscount.setVisibility(GONE);
    maxCouponAmount.setVisibility(GONE);

    final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) amountContainer.getLayoutParams();
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    params.addRule(RelativeLayout.ALIGN_PARENT_END);

    amountContainer.setLayoutParams(params);
    arrow.setVisibility(GONE);
}
 
Example 9
Source File: OptionPositionBuilder.java    From YMenuView with Apache License 2.0 5 votes vote down vote up
@Override
public void finish(){
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(mWidth,mHeight);

    if (mMarginOrientationX == MARGIN_LEFT){
        layoutParams.leftMargin = mXMargin;
        if (mIsAlignMenuButtonX){
            layoutParams.addRule(RIGHT_OF,mMenuButton.getId());
        }else {
            layoutParams.addRule(ALIGN_PARENT_LEFT);
        }
    }else {
        layoutParams.rightMargin = mXMargin;
        if (mIsAlignMenuButtonX){
            layoutParams.addRule(LEFT_OF,mMenuButton.getId());
        }else {
            layoutParams.addRule(ALIGN_PARENT_RIGHT);
        }
    }
    if (mMarginOrientationY == MARGIN_TOP){
        layoutParams.topMargin = mYMargin;
        if (mIsAlignMenuButtonY){
            layoutParams.addRule(BELOW,mMenuButton.getId());
        }else {
            layoutParams.addRule(ALIGN_PARENT_TOP);
        }
    }else {
        layoutParams.bottomMargin = mYMargin;
        if (mIsAlignMenuButtonY){
            layoutParams.addRule(ABOVE,mMenuButton.getId());
        }else {
            layoutParams.addRule(ALIGN_PARENT_BOTTOM);
        }
    }
    mOptionButton.setLayoutParams(layoutParams);
}
 
Example 10
Source File: ExceptionFragment.java    From apollo-DuerOS with Apache License 2.0 5 votes vote down vote up
private void changeUILayout() {
    RelativeLayout.LayoutParams params = null;
    
    params = (RelativeLayout.LayoutParams) mDisplayImgView.getLayoutParams();
    params.setMargins(0, 0, 0, 0);
    params.height = 200;
    mDisplayImgView.setLayoutParams(params);
    
    params = (RelativeLayout.LayoutParams) mDisplayTextView.getLayoutParams();
    params.setMargins(0, 0, 0, 0);
    mDisplayTextView.setLayoutParams(params);
    mDisplayTextView.setTextSize(22.0f);
    
    mContentView.invalidate();
}
 
Example 11
Source File: BubbleImg.java    From Android with MIT License 5 votes vote down vote up
public void initView() {
    context = getContext();

    RelativeLayout.LayoutParams proParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    proParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    progressBar = new ProgressBar(getContext());
    progressBar.setLayoutParams(proParams);
    addView(progressBar, proParams);

    RelativeLayout.LayoutParams imgParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    imageView = new ImageView(getContext());
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    addView(imageView, imgParams);
}
 
Example 12
Source File: PlayActivity.java    From AnimeTaste with MIT License 5 votes vote down vote up
private void setMinSize() {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getSupportActionBar().show();
    RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
            Screen.getScreenWidth(getWindowManager()), getResources()
            .getDimensionPixelSize(R.dimen.player_height));
    mHeaderWrapper.setLayoutParams(param);
    mVV.setLayoutParams(param);
    mZoomButton.setBackgroundResource(R.drawable.screensize_zoomout_button);
    mCurrentScape = OrientationHelper.PORTRAIT;
}
 
Example 13
Source File: DefaultHeaderTransformer.java    From Bitocle with Apache License 2.0 5 votes vote down vote up
private void applyProgressBarStyle() {
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, mProgressBarHeight);

    switch (mProgressBarStyle) {
        case PROGRESS_BAR_STYLE_INSIDE:
            lp.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.ptr_content);
            break;
        case PROGRESS_BAR_STYLE_OUTSIDE:
            lp.addRule(RelativeLayout.BELOW, R.id.ptr_content);
            break;
    }

    mHeaderProgressBar.setLayoutParams(lp);
}
 
Example 14
Source File: EditPagePort.java    From enjoyshop with Apache License 2.0 4 votes vote down vote up
private void initTitle(RelativeLayout rlTitle, float ratio) {
	tvCancel = new TextView(activity);
	tvCancel.setTextColor(0xff3b3b3b);
	tvCancel.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
	tvCancel.setGravity(Gravity.CENTER);
	int resId = ResHelper.getStringRes(activity, "ssdk_oks_cancel");
	if (resId > 0) {
		tvCancel.setText(resId);
	}
	int padding = (int) (DESIGN_LEFT_PADDING * ratio);
	tvCancel.setPadding(padding, 0, padding, 0);
	RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	rlTitle.addView(tvCancel, lp);
	tvCancel.setOnClickListener(this);

	TextView tvTitle = new TextView(activity);
	tvTitle.setTextColor(0xff3b3b3b);
	tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
	tvTitle.setGravity(Gravity.CENTER);
	resId = ResHelper.getStringRes(activity, "ssdk_oks_multi_share");
	if (resId > 0) {
		tvTitle.setText(resId);
	}
	lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	lp.addRule(RelativeLayout.CENTER_IN_PARENT);
	rlTitle.addView(tvTitle, lp);

	tvShare = new TextView(activity);
	tvShare.setTextColor(0xffff6d11);
	tvShare.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
	tvShare.setGravity(Gravity.CENTER);
	resId = ResHelper.getStringRes(activity, "ssdk_oks_share");
	if (resId > 0) {
		tvShare.setText(resId);
	}
	tvShare.setPadding(padding, 0, padding, 0);
	lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
	rlTitle.addView(tvShare, lp);
	tvShare.setOnClickListener(this);
}
 
Example 15
Source File: MainActivity.java    From Rey-MusicPlayer with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mContext = this;

    mFragments = new ArrayList<>();
    mTabLayout = findViewById(R.id.id_tabs);
    mViewPager = findViewById(R.id.view_pager);

    String[] tabs=getTabs();
    mAdapter = new SwipeAdapter(getSupportFragmentManager(),tabs);

    mViewPager.setAdapter(mAdapter);

    setDefaultTab(tabs);

    mViewPager.setOffscreenPageLimit(5);

    mTabLayout.setupWithViewPager(mViewPager);

    MusicUtils.changeTabsFont(mContext, mTabLayout);
    MusicUtils.applyFontForToolbarTitle(this);
    mToolbar = findViewById(R.id.toolbar);
    mAppBarLayout = findViewById(R.id.id_toolbar_container);


    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mAppBarLayout.getLayoutParams();
    params.topMargin = Common.getStatusBarHeight(this);
    mAppBarLayout.setLayoutParams(params);


    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    mToolbar.setNavigationOnClickListener(v -> {
        onPrepareOptionsMenu(mMenu);
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        getSupportActionBar().setDisplayShowHomeEnabled(false);
    });

}
 
Example 16
Source File: CustomHintContentHolder.java    From hintcase with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(Context context, final HintCase hintCase, ViewGroup parent) {
    this.hintCase = hintCase;
    this.parent = parent;

    calculateDataToPutTheArroW(hintCase);
    setArrow(context);

    FrameLayout.LayoutParams frameLayoutParamsBlock = getParentLayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT,
            gravity, marginLeft, marginTop, marginRight, marginBottom);

    RelativeLayout fullBlockLayout = new RelativeLayout(context);
    fullBlockLayout.setLayoutParams(frameLayoutParamsBlock);

    RelativeLayout.LayoutParams relativeLayoutParamsLinear =
            new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
    for (int rule : alignBlockRules) {
        relativeLayoutParamsLinear.addRule(rule);
    }
    relativeLayoutParamsLinear.topMargin = contentTopMargin;
    relativeLayoutParamsLinear.bottomMargin = contentBottomMargin;
    relativeLayoutParamsLinear.rightMargin = contentRightMargin;
    relativeLayoutParamsLinear.leftMargin = contentLeftMargin;
    contentLinearLayout = new LinearLayout(context);
    contentLinearLayout.setBackgroundResource(R.drawable.bubble_border_background);
    LayerDrawable layerDrawable = (LayerDrawable) contentLinearLayout.getBackground().getCurrent();
    GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable.getDrawable(layerDrawable.getNumberOfLayers() - 1);
    gradientDrawable.setColor(backgroundColor);
    if (useBorder) {
        gradientDrawable.setStroke(borderSize, borderColor);
    }

    contentLinearLayout.setLayoutParams(relativeLayoutParamsLinear);
    contentLinearLayout.setGravity(Gravity.CENTER);
    int padding = borderSize + shadowSize;
    contentLinearLayout.setPadding(padding + contentLeftPadding,
            padding + contentTopPadding,
            padding + contentRightPadding,
            padding + contentBottomPadding);
    contentLinearLayout.setOrientation(LinearLayout.VERTICAL);

    if (contentTitle != null) {
        contentLinearLayout.addView(getTextViewTitle(context));
    }
    if (existImage()) {
        contentLinearLayout.addView(getImage(context, imageView, imageResourceId));
    }
    if (contentText != null) {
        contentLinearLayout.addView(getTextViewDescription(context));
    }
    fullBlockLayout.addView(contentLinearLayout);
    fullBlockLayout.addView(arrow);
    return fullBlockLayout;
}
 
Example 17
Source File: MainActivity.java    From WanDaoJiaIndex with Apache License 2.0 4 votes vote down vote up
private void setTopMargin(View v, int topMargin){
	RelativeLayout.LayoutParams lp = (android.widget.RelativeLayout.LayoutParams) v.getLayoutParams();
	lp.topMargin = topMargin;
	v.setLayoutParams(lp);
}
 
Example 18
Source File: GuideView.java    From GuideView with MIT License 4 votes vote down vote up
private void addHintView() {
    if (hasAddHintView || bundle.getHintView() == null) {
        return;
    }

    RelativeLayout.LayoutParams params = bundle.getHintViewParams() == null ? new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) : bundle.getHintViewParams();
    int left, top, right, bottom;
    left = top = right = bottom = 0;
    int gravity = Gravity.TOP | Gravity.START;
    int viewHeight = decorView.getHeight();
    // below android 4.4,it can not set the status bar transparent,so we need the calculate the height of it to settle the hintView on correct position
    int extraHeight = Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT ? Utils.getStatusBarHeight(getContext()) : 0;
    switch (bundle.getHintViewDirection()) {
        case LEFT:
            gravity = Gravity.END;
            top = targetViewLocation[1] + bundle.getHintViewMarginTop();
            right = screenWidth - targetViewLocation[0] + bundle.getHintViewMarginRight() + bundle.getTransparentSpaceLeft() ;
            break;
        case RIGHT:
            gravity = Gravity.START;
            top = targetViewLocation[1] + bundle.getHintViewMarginTop();
            left = targetViewLocation[0] + targetViewWidth + bundle.getHintViewMarginLeft() + bundle.getTransparentSpaceRight() ;
            break;
        case TOP:
            gravity = Gravity.BOTTOM;
            bottom = viewHeight - targetViewLocation[1] + bundle.getHintViewMarginBottom() + bundle.getTransparentSpaceTop();
            left = targetViewLocation[0] + bundle.getHintViewMarginLeft();
            break;
        case BOTTOM:
            gravity = Gravity.TOP;
            top = targetViewLocation[1] + targetViewHeight + bundle.getHintViewMarginTop() + bundle.getTransparentSpaceBottom() - extraHeight;
            left = targetViewLocation[0] + bundle.getHintViewMarginLeft();
            break;
    }
    setGravity(gravity);
    params.setMargins(left, top, right, bottom);
    if (bundle.getHintView().getParent() != null) {
        bundle.getHintView().setLayoutParams(params);
    } else {
        this.addView(bundle.getHintView(), params);
    }
    hasAddHintView = true;
}
 
Example 19
Source File: RecentTabsGroupView.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private static void replaceRule(View view, int oldRule, int newRule) {
    RelativeLayout.LayoutParams lp = ((RelativeLayout.LayoutParams) view.getLayoutParams());
    lp.addRule(oldRule, 0);
    lp.addRule(newRule);
}
 
Example 20
Source File: MainActivity.java    From FontTextView with MIT License 4 votes vote down vote up
@Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.set_path_button:
                mFontTextView.setFontPath("fonts/my_font.ttf");
                break;
            case R.id.create_button:
                v.setEnabled(false);    // can click only once
                ViewGroup parent = (ViewGroup) findViewById(R.id.container_layout);
                createFontTextView(parent, "fonts/my_font.ttf");
//                createTextView(parent, "fonts/my_font.ttf");
                break;
            case R.id.replace_font_from_asset_btn:
                /* Method 3: replace system default font */
                FontUtils.getInstance().replaceSystemDefaultFontFromAsset(this, "fonts/my_font.ttf");
                recreate();
                break;
            case R.id.replace_font_from_file_btn:
                if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
                    String fontPath = Environment.getExternalStorageDirectory() + "/whinc/my_font.ttf";
                    FontUtils.getInstance().replaceSystemDefaultFontFromFile(this, fontPath);
                    recreate();
                } else {
                    Toast.makeText(this, "External storage is not accessible!", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.add_view_btn:
                v.setEnabled(false);    // can click only once
                Button button = new Button(this, null, R.attr.buttonStyle);
                button.setText("Button");
                RelativeLayout layout = (RelativeLayout) findViewById(R.id.font_text_layout);
                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT
                );
                lp.addRule(RelativeLayout.CENTER_IN_PARENT);
                layout.addView(button, lp);
                break;
            default:
                break;
        }
    }