下面列出了android.widget.RadioButton#setLayoutParams ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@NonNull
private RadioButton initData(int length, int i, Object imagepath) {
initImageView(i, imagepath);
RadioButton radioButton = new RadioButton(context);
if (selectTab != 0) {
radioButton.setBackgroundResource(selectTab);
radioButton.setButtonDrawable(context.getResources().getDrawable(android.R.color.transparent));
}
RadioGroup.LayoutParams buttonParams = new RadioGroup.LayoutParams(tabWidth, tabHeight);
if (i != length - 1) {
buttonParams.setMargins(0, 0, tabMargin, 0);
}
radioButton.setLayoutParams(buttonParams);
radioButton.setId(i);
if (i == 0) radioButton.setChecked(true);
return radioButton;
}
private void createRadioButtons() {
// set button dimension
int buttonSize = AptoideUtils.ScreenU.getPixelsForDip(10, getResources());
ViewGroup.LayoutParams buttonLayoutParams = new RadioGroup.LayoutParams(buttonSize, buttonSize);
// set button margin
int buttonMargin = AptoideUtils.ScreenU.getPixelsForDip(2, getResources());
ViewGroup.MarginLayoutParams marginLayoutParams =
(ViewGroup.MarginLayoutParams) buttonLayoutParams;
marginLayoutParams.setMargins(buttonMargin, buttonMargin, buttonMargin, buttonMargin);
final int pages = viewPagerAdapter.getCount();
wizardButtons = new ArrayList<>(pages);
Context context = getContext();
for (int i = 0; i < pages; i++) {
RadioButton radioButton = new RadioButton(context);
radioButton.setLayoutParams(buttonLayoutParams);
radioButton.setButtonDrawable(android.R.color.transparent);
radioButton.setBackgroundResource(R.drawable.wizard_custom_indicator);
radioButton.setClickable(false);
radioGroup.addView(radioButton);
wizardButtons.add(radioButton);
}
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
removeAllViews();
for (int i = 0; i < pageCount; i++) {
RadioButton rb = new RadioButton(getContext());
rb.setFocusable(false);
rb.setClickable(false);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
Drawable d = ContextCompat.getDrawable(getContext(), R.drawable.indicator);
rb.setButtonDrawable(d);
LinearLayout.LayoutParams params = generateDefaultLayoutParams();
params.width = d.getIntrinsicWidth();
params.height = d.getIntrinsicHeight();
rb.setLayoutParams(params);
} else {
rb.setButtonDrawable(R.drawable.indicator);
}
addView(rb);
}
setCurrentPosition(-1);
}
protected RadioButton getRadioButton(Integer id, String text, String tag, String value) {
RadioButton radioButton = new RadioButton(getActivity());
radioButton.setId(id);
radioButton.setText(text);
radioButton.setTag(tag);
radioButton.setTextAppearance(getActivity(), R.style.RadioButton_Full);
radioButton.setLayoutParams(getLayoutParams(labelDescription.getPaddingLeft(), labelDescription.getPaddingLeft() / 2, labelDescription.getPaddingRight(), labelDescription.getPaddingLeft() / 2));
if (value != null && value.equals(tag)) {
radioButton.setChecked(true);
}
else {
radioButton.setChecked(false);
}
return radioButton;
}