下面列出了android.widget.CheckBox#setLayoutParams ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void setUpCodeViews() {
removeAllViews();
mCodeViews.clear();
mCode = "";
for (int i = 0; i < mCodeLength; i++) {
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
CheckBox view = (CheckBox) inflater.inflate(R.layout.view_pf_code_checkbox, null);
LinearLayout.LayoutParams layoutParams = new LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
int margin = getResources().getDimensionPixelSize(R.dimen.code_fp_margin);
layoutParams.setMargins(margin, margin, margin, margin);
view.setLayoutParams(layoutParams);
view.setChecked(false);
addView(view);
mCodeViews.add(view);
}
if (mListener != null) {
mListener.onCodeNotCompleted("");
}
}
private void initPreCheckBox() {
mPreCheckoutBox = new CheckBox(mContext);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
mPreCheckoutBox.setText(openDebugTxt);
mPreCheckoutBox.setLayoutParams(params);
mPreCheckoutBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
if (isChecked && mDebugCheckBox.isChecked()) {
mDebugCheckBox.setChecked(false);
}
}
});
}
protected void loadUserList() {
LinearLayout userListContainer = (LinearLayout)findViewById(R.id.user_list_container);
ArrayList<UserSnsInfo> userSnsList = Share.snsData.userSnsList;
checkBoxList.clear();
userListContainer.removeAllViews();
for (int i=0;i<userSnsList.size();i++) {
CheckBox userCheckBox = new CheckBox(this);
userCheckBox.setText(userSnsList.get(i).userName + "(" + userSnsList.get(i).userId + ")" + "(" + String.format(getString(R.string.user_moment_count), userSnsList.get(i).snsList.size()) + ")");
userListContainer.addView(userCheckBox);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)userCheckBox.getLayoutParams();
layoutParams.setMargins(5, 5, 5, 5);
userCheckBox.setLayoutParams(layoutParams);
userCheckBox.setChecked(true);
userCheckBox.setTag(userSnsList.get(i).userId);
checkBoxList.add(userCheckBox);
}
}
public EmailAutoCompleteLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
// Can't call through to super(Context, AttributeSet, int) since it doesn't exist on API 10
super(context, attrs);
backgroundPermissionManager = new BackgroundPermissionManager(this, context);
setOrientation(LinearLayout.VERTICAL);
setAddStatesFromChildren(true);
final TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.EmailAutoCompleteLayout, defStyleAttr, defStyleRes);
CharSequence permissionText = a.getText(R.styleable.EmailAutoCompleteLayout_permissionText);
if (permissionText == null) {
permissionText = context.getString(R.string.message_get_accounts_permission);
}
a.recycle();
permissionPrimer = new CheckBox(context);
permissionPrimer.setTextColor(0x8a000000);
permissionPrimer.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
permissionPrimer.setText(permissionText);
addView(permissionPrimer);
}
@NonNull
@Override
protected ScrollView makeCenterView() {
ScrollView scrollView = new ScrollView(activity);
layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.VERTICAL);
for (String item : items) {
LinearLayout line = new LinearLayout(activity);
line.setOrientation(LinearLayout.HORIZONTAL);
line.setGravity(Gravity.CENTER);
TextView textView = new TextView(activity);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, WRAP_CONTENT, 1.0f);
lp.gravity = Gravity.CENTER;
textView.setLayoutParams(lp);
textView.setText(item);
textView.setGravity(Gravity.CENTER);
line.addView(textView);
CheckBox checkBox = new CheckBox(activity);
checkBox.setLayoutParams(new LinearLayout.LayoutParams(0, WRAP_CONTENT, 0.4f));
line.addView(checkBox);
layout.addView(line);
}
scrollView.addView(layout);
return scrollView;
}
private void initLoggingCheckBox() {
mLogCheckBox = new CheckBox(mContext);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
mLogCheckBox.setText("是否开启log信息?");
mLogCheckBox.setLayoutParams(params);
}
private void initDebugCheckBox() {
mDebugCheckBox = new CheckBox(mContext);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
mDebugCheckBox.setLayoutParams(params);
mDebugCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
if (isChecked && mPreCheckoutBox.isChecked()) {
mPreCheckoutBox.setChecked(false);
}
}
});
}
public BaseDialog setCheckBoxName(List<String> list) {
if (middleLayout.getChildCount() > 0) {
middleLayout.removeAllViews();
}
for (String title :
list) {
TextView textView = new TextView(getContext());
textView.setGravity(Gravity.START);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.weight = 1;
textView.setLayoutParams(layoutParams);
textView.setText(title);
final CheckBox checkBox = new CheckBox(getContext());
checkBox.setGravity(Gravity.END);
LinearLayout.LayoutParams checkBoxLayout = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
checkBoxLayout.weight = 1;
checkBox.setLayoutParams(checkBoxLayout);
LinearLayout linearLayout = new LinearLayout(getContext());
LinearLayout.LayoutParams linearLayoutParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
linearLayout.setGravity(Gravity.CENTER_VERTICAL);
linearLayout.setWeightSum(2);
linearLayout.setLayoutParams(linearLayoutParam);
linearLayout.addView(textView);
linearLayout.addView(checkBox);
middleLayout.addView(linearLayout);
}
return this;
}
public BaseDialog setCheckBoxName(List<String> list) {
if (middleLayout.getChildCount() > 0) {
middleLayout.removeAllViews();
}
for (String title :
list) {
TextView textView = new TextView(getContext());
textView.setGravity(Gravity.START);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.weight = 1;
textView.setLayoutParams(layoutParams);
textView.setText(title);
final CheckBox checkBox = new CheckBox(getContext());
checkBox.setGravity(Gravity.END);
LinearLayout.LayoutParams checkBoxLayout = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
checkBoxLayout.weight = 1;
checkBox.setLayoutParams(checkBoxLayout);
LinearLayout linearLayout = new LinearLayout(getContext());
LinearLayout.LayoutParams linearLayoutParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
linearLayout.setGravity(Gravity.CENTER_VERTICAL);
linearLayout.setWeightSum(2);
linearLayout.setLayoutParams(linearLayoutParam);
linearLayout.addView(textView);
linearLayout.addView(checkBox);
middleLayout.addView(linearLayout);
}
return this;
}
public BaseDialog setCheckBoxName(List<String> list) {
if (middleLayout.getChildCount() > 0) {
middleLayout.removeAllViews();
}
for (String title :
list) {
TextView textView = new TextView(getContext());
textView.setGravity(Gravity.START);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.weight = 1;
textView.setLayoutParams(layoutParams);
textView.setText(title);
final CheckBox checkBox = new CheckBox(getContext());
checkBox.setGravity(Gravity.END);
LinearLayout.LayoutParams checkBoxLayout = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
checkBoxLayout.weight = 1;
checkBox.setLayoutParams(checkBoxLayout);
LinearLayout linearLayout = new LinearLayout(getContext());
LinearLayout.LayoutParams linearLayoutParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
linearLayout.setGravity(Gravity.CENTER_VERTICAL);
linearLayout.setWeightSum(2);
linearLayout.setLayoutParams(linearLayoutParam);
linearLayout.addView(textView);
linearLayout.addView(checkBox);
middleLayout.addView(linearLayout);
}
return this;
}
protected void loadUserList() {
LinearLayout userListContainer = (LinearLayout)findViewById(R.id.user_list_container);
//ArrayList<UserSnsInfo> userSnsList = Share.snsData.userSnsList;
checkBoxList.clear();
userListContainer.removeAllViews();
//userSnsList.get(i).snsList.size();
ArrayList<UserSnsInfo> snsSizeRank = Share.snsData.userSnsList;//new ArrayList<UserSnsInfo>(userSnsList);
Collections.sort(snsSizeRank, new Comparator<UserSnsInfo>() {
@Override
public int compare(UserSnsInfo lhs, UserSnsInfo rhs) {
if (rhs.snsList.size() - lhs.snsList.size() > 0) {
return 1;
} else if (rhs.snsList.size() - lhs.snsList.size() < 0) {
return -1;
} else {
return 0;
}
}
});
UserSnsInfo userSnsInfo2=null;
for (int i=0;i<snsSizeRank.size();i++) {
userSnsInfo2 = snsSizeRank.get(i);
CheckBox userCheckBox = new CheckBox(this);
userCheckBox.setText(userSnsInfo2.authorName + "(" + userSnsInfo2.userId + ")" + "(" + String.format(getString(R.string.user_moment_count), userSnsInfo2.snsList.size()) + ")");
userListContainer.addView(userCheckBox);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)userCheckBox.getLayoutParams();
layoutParams.setMargins(5, 5, 5, 5);
userCheckBox.setLayoutParams(layoutParams);
userCheckBox.setChecked(true);
userCheckBox.setTag(userSnsInfo2.userId);
checkBoxList.add(userCheckBox);
}
}
/**
* @param context the context to use.
* @param attrs attributes.
* @param parentView parent
* @param label label
* @param value value
* @param constraintDescription constraints
* @param readonly if <code>false</code>, the item is disabled for editing.
*/
public GBooleanView(Context context, AttributeSet attrs, LinearLayout parentView, String label, String value,
String constraintDescription, boolean readonly) {
super(context, attrs);
LinearLayout textLayout = new LinearLayout(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(10, 10, 10, 10);
textLayout.setLayoutParams(layoutParams);
textLayout.setOrientation(LinearLayout.VERTICAL);
parentView.addView(textLayout);
TextView textView = new TextView(context);
textView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
textView.setPadding(2, 2, 2, 2);
textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
textView.setTextColor(Compat.getColor(context, R.color.formcolor));
textLayout.addView(textView);
checkbox = new CheckBox(context);
checkbox.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
checkbox.setPadding(15, 5, 15, 5);
if (value != null) {
if (value.trim().toLowerCase().equals("true")) { //$NON-NLS-1$
checkbox.setChecked(true);
} else {
checkbox.setChecked(false);
}
}
checkbox.setEnabled(!readonly);
textLayout.addView(checkbox);
}
private void initReportCheckBox() {
mReportCheckBox = new CheckBox(mContext);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
mReportCheckBox.setLayoutParams(params);
}
@SuppressLint("RtlHardcoded")
public TextDetailDocumentsCell(Context context) {
super(context);
density = context.getResources().getDisplayMetrics().density;
checkDisplaySize();
textView = new TextView(context);
textView.setTextColor(0xff212121);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
textView.setLines(1);
textView.setMaxLines(1);
textView.setSingleLine(true);
textView.setGravity(Gravity.LEFT);
addView(textView);
LayoutParams layoutParams = (LayoutParams) textView.getLayoutParams();
layoutParams.width = LayoutParams.WRAP_CONTENT;
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.topMargin = AndroidUtilities.dp(10, density);
layoutParams.leftMargin = AndroidUtilities.dp(71, density);
layoutParams.rightMargin = AndroidUtilities.dp(16, density);
layoutParams.gravity = Gravity.LEFT;
textView.setLayoutParams(layoutParams);
valueTextView = new TextView(context);
valueTextView.setTextColor(0xff8a8a8a);
valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
valueTextView.setLines(1);
valueTextView.setMaxLines(1);
valueTextView.setSingleLine(true);
valueTextView.setGravity(Gravity.LEFT);
addView(valueTextView);
layoutParams = (LayoutParams) valueTextView.getLayoutParams();
layoutParams.width = LayoutParams.WRAP_CONTENT;
layoutParams.height = LayoutParams.WRAP_CONTENT;
layoutParams.topMargin = AndroidUtilities.dp(35, density);
layoutParams.leftMargin = AndroidUtilities.dp(71, density);
layoutParams.rightMargin = AndroidUtilities.dp(16, density);
layoutParams.gravity = Gravity.LEFT;
valueTextView.setLayoutParams(layoutParams);
typeTextView = new TextView(context);
typeTextView.setBackgroundColor(0xff757575);
typeTextView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
typeTextView.setGravity(Gravity.CENTER);
typeTextView.setSingleLine(true);
typeTextView.setTextColor(0xffd1d1d1);
typeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
typeTextView.setTypeface(Typeface.DEFAULT_BOLD);
addView(typeTextView);
layoutParams = (LayoutParams) typeTextView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(40, density);
layoutParams.height = AndroidUtilities.dp(40, density);
layoutParams.leftMargin = AndroidUtilities.dp(16, density);
layoutParams.rightMargin = AndroidUtilities.dp(0, density);
layoutParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
typeTextView.setLayoutParams(layoutParams);
imageView = new ImageView(context);
addView(imageView);
layoutParams = (LayoutParams) imageView.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(40, density);
layoutParams.height = AndroidUtilities.dp(40, density);
layoutParams.leftMargin = AndroidUtilities.dp(16, density);
layoutParams.rightMargin = AndroidUtilities.dp(0, density);
layoutParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
imageView.setLayoutParams(layoutParams);
checkBox = new CheckBox(context);
checkBox.setVisibility(GONE);
addView(checkBox);
layoutParams = (LayoutParams) checkBox.getLayoutParams();
layoutParams.width = AndroidUtilities.dp(22, density);
layoutParams.height = AndroidUtilities.dp(22, density);
layoutParams.topMargin = AndroidUtilities.dp(34, density);
layoutParams.leftMargin = AndroidUtilities.dp(38, density) ;
layoutParams.rightMargin = 0;
layoutParams.gravity = Gravity.LEFT;
checkBox.setLayoutParams(layoutParams);
}
@Override
protected void onBindDialogView(View view) {
LinearLayout container = view.findViewById(R.id.layoutContainer);
linearLayouts.clear();
checkBoxes.clear();
ArrayList<Integer> results = lg.getMenuShownList();
gameOrder = lg.getOrderedGameList();
TypedValue typedValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
int padding = (int) (getContext().getResources().getDimension(R.dimen.dialog_menu_layout_padding));
int margin = (int) (getContext().getResources().getDimension(R.dimen.dialog_menu_button_margin));
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(margin, 0, margin, 0);
ArrayList<String> sortedGameList = lg.getOrderedGameNameList(getContext().getResources());
for (int i = 0; i < lg.getGameCount(); i++) {
LinearLayout entry = new LinearLayout(getContext());
entry.setBackgroundResource(typedValue.resourceId);
entry.setPadding(padding, padding, padding, padding);
entry.setOnClickListener(this);
CheckBox checkBox = new CheckBox(getContext());
checkBox.setLayoutParams(layoutParams);
int index = gameOrder.indexOf(i);
checkBox.setChecked(results.get(index) == 1);
TextView textView = new TextView(getContext());
textView.setTypeface(null, Typeface.BOLD);
textView.setText(sortedGameList.get(i));
entry.addView(checkBox);
entry.addView(textView);
checkBoxes.add(checkBox);
linearLayouts.add(entry);
container.addView(entry);
}
super.onBindDialogView(view);
}
public void initControl() {
mReady = false;
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
removeAllViews();
setOrientation(VERTICAL);
if (isEditable()) {
if (mWidget != null) {
switch (mWidget) {
case Switch:
mSwitch = new Switch(mContext);
mSwitch.setLayoutParams(params);
mSwitch.setOnCheckedChangeListener(this);
setValue(getValue());
if (mLabel != null)
mSwitch.setText(mLabel);
if (textSize > -1) {
mSwitch.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
if (appearance > -1) {
mSwitch.setTextAppearance(mContext, appearance);
}
mSwitch.setTextColor(textColor);
addView(mSwitch);
break;
default:
break;
}
} else {
mCheckbox = new CheckBox(mContext);
mCheckbox.setLayoutParams(params);
mCheckbox.setOnCheckedChangeListener(this);
if (mLabel != null)
mCheckbox.setText(mLabel);
if (textSize > -1) {
mCheckbox.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
if (appearance > -1) {
mCheckbox.setTextAppearance(mContext, appearance);
}
mCheckbox.setTextColor(textColor);
addView(mCheckbox);
}
} else {
txvView = new TextView(mContext);
txvView.setLayoutParams(params);
txvView.setText(getCheckBoxLabel());
if (mLabel != null)
txvView.setText(mLabel);
if (textSize > -1) {
txvView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
if (appearance > -1) {
txvView.setTextAppearance(mContext, appearance);
}
addView(txvView);
}
}
public void initControl() {
mReady = false;
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
removeAllViews();
setOrientation(VERTICAL);
if (isEditable()) {
if (mWidget != null) {
switch (mWidget) {
case Switch:
mSwitch = new Switch(mContext);
mSwitch.setLayoutParams(params);
mSwitch.setOnCheckedChangeListener(this);
setValue(getValue());
if (mLabel != null)
mSwitch.setText(mLabel);
if (textSize > -1) {
mSwitch.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
if (appearance > -1) {
mSwitch.setTextAppearance(mContext, appearance);
}
mSwitch.setTextColor(textColor);
addView(mSwitch);
break;
default:
break;
}
} else {
mCheckbox = new CheckBox(mContext);
mCheckbox.setLayoutParams(params);
mCheckbox.setOnCheckedChangeListener(this);
if (mLabel != null)
mCheckbox.setText(mLabel);
if (textSize > -1) {
mCheckbox.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
if (appearance > -1) {
mCheckbox.setTextAppearance(mContext, appearance);
}
mCheckbox.setTextColor(textColor);
addView(mCheckbox);
}
} else {
txvView = new TextView(mContext);
txvView.setLayoutParams(params);
txvView.setText(getCheckBoxLabel());
if (mLabel != null)
txvView.setText(mLabel);
if (textSize > -1) {
txvView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
if (appearance > -1) {
txvView.setTextAppearance(mContext, appearance);
}
addView(txvView);
}
}