radioButton.setChecked(false); radioButton.setId(id++); radioButton.setLayoutParams(new RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); radioButton.setOnClickListener(radioButtonsClickListener); radioGroup.addView(radioButton);
private void setOptionUseAccountMarginStart(int marginStart) { LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) optionUseAccount.getLayoutParams(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { layoutParams.setMarginStart(marginStart); } else { layoutParams.leftMargin = marginStart; } optionUseAccount.setLayoutParams(layoutParams); }
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER); radio.setLayoutParams(l); radio.setGravity(Gravity.CENTER); radio.setPadding(20, 20, 20, 20);
RadioButton mRadioButton = mRadioArrays.get(i, createRadioView()); mParams.leftMargin = i > 0 ? -strokeWidth : 0; mRadioButton.setLayoutParams(i == 0 ? mFirstParams : mParams); mRadioButton.setButtonDrawable(mButtonDrawables != null ? mButtonDrawables.get(i, colorDrawable) : colorDrawable); if (Build.VERSION.SDK_INT >= 16) {
/** * 创建子 tab * * @param context * @param id */ public static RadioButton creatTabItem(Context context, int id, String text) { final int width = DensityUtil.dip2px(context, 80); final int height = DensityUtil.dip2px(context, 46); final int padding = DensityUtil.dip2px(context, 3); RadioButton button; button = new RadioButton(context); button.setId(id); // button.setWidth(width); // button.setHeight(height); button.setText(text); button.setLayoutParams(new LinearLayout.LayoutParams(width, height)); button.setHeight(height); button.setBackgroundResource(R.drawable.tab_item_bg_selector); button.setButtonDrawable(context.getResources().getDrawable(android.R.color.transparent)); button.setGravity(Gravity.CENTER); button.setTextColor(context.getResources().getColorStateList(R.color.tab_item_font_color_selector)); button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); button.setPadding(0, 0, 0, padding); return button; } }
params.setMargins(DisplayUtils.dp2px(context, 8), 0, 0, 0); rb.setLayoutParams(params); rb.setButtonDrawable(new ColorDrawable()); rb.setBackgroundResource(R.drawable.shape_oval_primary2white_sel);
@Override RadioGroup createWidgetView(AppCompatActivity activity) { radioGroup = new RadioGroup(activity); radioGroup.setPadding(16, 16, 16, 16); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); layoutParams.topMargin = 32; layoutParams.bottomMargin = 32; String[] values = getInputValues(activity.getIntent()); for (int j = 0; j < values.length; ++j) { String value = values[j]; RadioButton button = new RadioButton(activity); button.setText(value); button.setId(j); button.setTextSize(18); button.setPadding(16, 16, 16, 16); button.setLayoutParams(layoutParams); radioGroup.addView(button); } return radioGroup; }
private void createRadioGroup() { final LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); if (mRadioGroup == null) { mRadioGroup = new RadioGroup(mContext); mRadioGroup.setLayoutParams(params); } else { removeView(mRadioGroup); } mRadioGroup.removeAllViews(); mRadioGroup.setOnCheckedChangeListener(this); for (ODataRow label : items) { RadioButton rdoBtn = new RadioButton(mContext); rdoBtn.setLayoutParams(params); rdoBtn.setText(label.getString(mModel.getDefaultNameColumn())); if (textSize > -1) { rdoBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); } if (appearance > -1) { rdoBtn.setTextAppearance(mContext, appearance); } rdoBtn.setTextColor(textColor); mRadioGroup.addView(rdoBtn); } addView(mRadioGroup); }