Gravity.CENTER); radio.setLayoutParams(l); radio.setGravity(Gravity.CENTER); radio.setPadding(20, 20, 20, 20);
private RadioButton createRadioView() { RadioButton mRadioButton = new RadioButton(getContext(), null, mRadioStyle > 0 ? mRadioStyle : android.R.attr.radioButtonStyle); if (mRadioStyle == 0) { mRadioButton.setGravity(Gravity.CENTER); mRadioButton.setEllipsize(TruncateAt.END); } if (mTextColor != null) mRadioButton.setTextColor(mTextColor); if (textSize > 0) mRadioButton.setTextSize(textSize); return mRadioButton; }
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { int radioButtonId = group.getCheckedRadioButtonId(); // 根据ID获取RadioButton的实例 RadioButton rb = (RadioButton) findViewById(radioButtonId); for (int i = 0; i < group.getChildCount(); i++) { RadioButton vradio = (RadioButton) group.getChildAt(i); vradio.setGravity(Gravity.CENTER); vradio.setPadding(20, 20, 20, 20); if (rb.getId() == vradio.getId()) { vradio.setTextColor(getResources().getColor(R.color.subject_select)); vradio.setChecked(true); vradio.setBackground(getResources().getDrawable(R.drawable.bg_bottom)); } else { vradio.setTextColor(getResources().getColor(R.color.kViewztblack)); vradio.setChecked(false); vradio.setBackground(null); } } // CustomProgress.show(mContext, true, null); kChartTimeInterval = titleList.get(checkedId - 1).get("time") + ""; indexMarketChart(); } });
/** * 创建子 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; } }