本文整理汇总了Java中android.widget.TextView.setLayoutParams方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.setLayoutParams方法的具体用法?Java TextView.setLayoutParams怎么用?Java TextView.setLayoutParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.setLayoutParams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initNormalPopupIfNeed
import android.widget.TextView; //导入方法依赖的package包/类
private void initNormalPopupIfNeed() {
if (mNormalPopup == null) {
mNormalPopup = new QMUIPopup(getContext(), QMUIPopup.DIRECTION_NONE);
TextView textView = new TextView(getContext());
textView.setLayoutParams(mNormalPopup.generateLayoutParam(
QMUIDisplayHelper.dp2px(getContext(), 250),
WRAP_CONTENT
));
textView.setLineSpacing(QMUIDisplayHelper.dp2px(getContext(), 4), 1.0f);
int padding = QMUIDisplayHelper.dp2px(getContext(), 20);
textView.setPadding(padding, padding, padding, padding);
textView.setText("Popup 可以设置其位置以及显示和隐藏的动画");
textView.setTextColor(ContextCompat.getColor(getContext(), R.color.app_color_description));
mNormalPopup.setContentView(textView);
mNormalPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
mActionButton1.setText(getContext().getResources().getString(R.string.popup_normal_action_button_text_show));
}
});
}
}
示例2: addView
import android.widget.TextView; //导入方法依赖的package包/类
public void addView(TextView childView, String text) {
if (push_state_ll.getChildCount() > 3) {
push_state_ll.removeViewAt(0);
}
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, 0, 0, 10);
childView.setTextColor(Color.RED);
childView.setText(text);
childView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13f);
childView.setBackgroundResource(R.drawable.text_state);
childView.setLayoutParams(layoutParams);
childView.setPadding(15, 10, 15, 10);
childView.setMaxEms(20);
childView.setMaxLines(3);
push_state_ll.addView(childView);
}
示例3: ToastProgress
import android.widget.TextView; //导入方法依赖的package包/类
public ToastProgress(android.content.Context context) {
super(context);
this.ctx=context;
this.h=new Handler();
this.h2=new Handler();
root = new LinearLayout(ctx);
root.setPadding((int)dp2px(ctx, 20), (int)dp2px(ctx, 10), (int)dp2px(ctx, 20), (int)dp2px(ctx, 10));
root.setOrientation(LinearLayout.HORIZONTAL);
prog=new ProgressBar(ctx);
prog.setLayoutParams(new LinearLayout.LayoutParams((int)dp2px(ctx, 20), (int)dp2px(ctx, 20)));
root.addView(prog);
clt=new TextView(ctx);
clt.setTextSize(14);
clt.setTextColor(Color.WHITE);
LinearLayout.LayoutParams tlp=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
tlp.gravity=Gravity.CENTER_VERTICAL;
tlp.setMargins((int)dp2px(ctx,10),0,0,0);
clt.setLayoutParams(tlp);
root.addView(clt);
shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
}
示例4: convert
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public void convert(EasyLVHolder holder, int position, String s) {
holder.setText(R.id.tvMinorItem, s);
if (current == position) {
holder.setVisible(R.id.ivMinorChecked, true);
} else {
holder.setVisible(R.id.ivMinorChecked, false);
}
if (position != 0) { // 子项右移
TextView textView = holder.getView(R.id.tvMinorItem);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textView.getLayoutParams();
params.leftMargin = ScreenUtils.dpToPxInt(25);
textView.setLayoutParams(params);
}
}
示例5: onCreate
import android.widget.TextView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout root = new LinearLayout(this);
root.setPadding(30, 30, 30, 30);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
root.setLayoutParams(lp);
setContentView(root);
// textView
TextView textView = new TextView(this);
textView.setText("Theme: Dialog");
textView.setGravity(Gravity.CENTER);
textView.setTextSize(30);
LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
textView.setLayoutParams(lp2);
root.addView(textView);
}
示例6: onBindViewHolder
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public void onBindViewHolder (RecyclerView.ViewHolder holder, int position) {
switch (holder.getItemViewType()) {
case 0:
LogViewHolder logViewHolder = (LogViewHolder) holder;
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
ProgressCard log = logs.get(position);
((LogViewHolder) holder).setWeightTitle(log.getTitle());
progress = log.getProgress();
for (short i = 0; i < progress.size(); i++) {
TextView newWeight = new TextView(((LogViewHolder) holder).getLinearLayout().getContext());
newWeight.setText(String.valueOf(progress.get(i)) + "lbs");
newWeight.setTextSize(42);
newWeight.setLayoutParams(lparams);
logViewHolder.linearLayoutWeigghts.addView(newWeight);
}
break;
case 2:
ProgressViewHolder progressViewHolder = (ProgressViewHolder) holder;
progressViewHolder.setWeightTitle(logs.get(position).getTitle());
}
}
示例7: TopHolder
import android.widget.TextView; //导入方法依赖的package包/类
TopHolder(View view) {
super(view);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.width = getScreenWidth(context) / 5;
item = new TextView(view.getContext());
item.setLayoutParams(params);
item.setMaxLines(1);
item.setEllipsize(TextUtils.TruncateAt.END);
item.setGravity(Gravity.CENTER);
item.setTextColor(ContextCompat.getColor(view.getContext(), R.color.gray_dark));
item.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(R.dimen.app_normal_margin));
item.setCompoundDrawablePadding(topPadding);
item.setPadding(0, padding, 0, padding);
TypedValue typedValue = new TypedValue();
view.getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
item.setBackgroundResource(typedValue.resourceId);
((LinearLayout) view).addView(item);
}
示例8: createDefaultTabView
import android.widget.TextView; //导入方法依赖的package包/类
/**
* Create a default view to be used for tabs. This is called if a custom tab view is not set via
* {@link #setCustomTabView(int, int)}.
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
protected TextView createDefaultTabView(Context context) {
TextView textView = new TextView(context);
textView.setGravity(Gravity.CENTER);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
outValue, true);
textView.setBackgroundResource(outValue.resourceId);
textView.setAllCaps(true);
int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
textView.setPadding(padding, padding, padding, padding);
return textView;
}
示例9: addItemView
import android.widget.TextView; //导入方法依赖的package包/类
private View addItemView(int rid, String text) {
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setId(rid);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, DensityUtil.dip2px(context, 44f)));
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setBackgroundResource(R.drawable.base_item_bg_selector);
linearLayout.setOnClickListener(this);
TextView textView = new TextView(context);
textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
textView.setText(text);
textView.setTextColor(context.getResources().getColor(R.color.bottom_dialog_textcolor));
textView.setTextSize(16f);
textView.setGravity(Gravity.CENTER);
linearLayout.removeAllViews();
linearLayout.addView(textView);
return linearLayout;
}
示例10: onBuildContent
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public View onBuildContent(QMUIDialog dialog, ScrollView parent) {
LinearLayout layout = new LinearLayout(mContext);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
int padding = QMUIDisplayHelper.dp2px(mContext, 20);
layout.setPadding(padding, padding, padding, padding);
mEditText = new EditText(mContext);
QMUIViewHelper.setBackgroundKeepingPadding(mEditText, QMUIResHelper.getAttrDrawable(mContext, R.attr.qmui_list_item_bg_with_border_bottom));
mEditText.setHint("输入框");
LinearLayout.LayoutParams editTextLP = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, QMUIDisplayHelper.dpToPx(50));
editTextLP.bottomMargin = QMUIDisplayHelper.dp2px(getContext(), 15);
mEditText.setLayoutParams(editTextLP);
layout.addView(mEditText);
TextView textView = new TextView(mContext);
textView.setLineSpacing(QMUIDisplayHelper.dp2px(getContext(), 4), 1.0f);
textView.setText("观察聚焦输入框后,键盘升起降下时 dialog 的高度自适应变化。\n\n" +
"QMUI Android 的设计目的是用于辅助快速搭建一个具备基本设计还原效果的 Android 项目," +
"同时利用自身提供的丰富控件及兼容处理,让开发者能专注于业务需求而无需耗费精力在基础代码的设计上。" +
"不管是新项目的创建,或是已有项目的维护,均可使开发效率和项目质量得到大幅度提升。");
textView.setTextColor(ContextCompat.getColor(getContext(), R.color.app_color_description));
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
layout.addView(textView);
return layout;
}
示例11: createTextView
import android.widget.TextView; //导入方法依赖的package包/类
private TextView createTextView(Context context, String s, int minHeight, int marginTop, int marginBottom, int marginLeftRight) {
TextView tv = new TextView(context);
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(marginLeftRight, marginTop, marginLeftRight, marginBottom);
tv.setLayoutParams(params);
tv.setText(s);
tv.setGravity(Gravity.CENTER);
tv.setMinHeight(minHeight);
tv.setTextAppearance(mContext, R.style.TextAppearance_AppCompat_Caption);
return tv;
}
示例12: showEmptyView
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public void showEmptyView() {
TextView textView = new TextView(ReviewActivity.this);
textView.setText(R.string.string_empty_tips);
textView.setTextSize(30);
textView.setBackgroundColor(Color.WHITE);
textView.setGravity(Gravity.CENTER);
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
textView.setLayoutParams(lp);
((ViewGroup)(findViewById(android.R.id.content))).addView(textView);
}
示例13: createLabelView
import android.widget.TextView; //导入方法依赖的package包/类
protected TextView createLabelView() {
TextView labelView = new TextView(activity);
labelView.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
labelView.setTextColor(textColorFocus);
labelView.setTextSize(textSize);
return labelView;
}
示例14: addResultListItem
import android.widget.TextView; //导入方法依赖的package包/类
public void addResultListItem(String title, String value, LinearLayout netLayout) {
final float scale = activity.getResources().getDisplayMetrics().density;
final int leftRightItem = Helperfunctions.dpToPx(5, scale);
final int topBottomItem = Helperfunctions.dpToPx(5, scale);
final int leftRightDiv = Helperfunctions.dpToPx(0, scale);
final int topBottomDiv = Helperfunctions.dpToPx(0, scale);
final int heightDiv = Helperfunctions.dpToPx(1, scale);
final int topBottomImg = Helperfunctions.dpToPx(1, scale);
final LinearLayout netItemLayout = new LinearLayout(activity);
netItemLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
netItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem, topBottomItem);
netItemLayout.setGravity(Gravity.CENTER_VERTICAL);
final TextView itemTitle = new TextView(activity, null, R.style.listResultItemTitle);
itemTitle.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 0.4f));
itemTitle.setWidth(0);
itemTitle.setGravity(Gravity.LEFT);
itemTitle.setText(title);
netItemLayout.addView(itemTitle);
final ImageView itemClassification = new ImageView(activity);
itemClassification.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.MATCH_PARENT, 0.1f));
itemClassification.setPadding(0, topBottomImg, 0, topBottomImg);
itemClassification.setImageDrawable(activity.getResources().getDrawable(
R.drawable.traffic_lights_none));
netItemLayout.addView(itemClassification);
final TextView itemValue = new TextView(activity, null, R.style.listResultItemValue);
itemValue.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 0.5f));
itemValue.setWidth(0);
itemValue.setGravity(Gravity.LEFT);
itemValue.setText(value);
netItemLayout.addView(itemValue);
netLayout.addView(netItemLayout);
final View divider = new View(activity);
divider.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv,
1));
divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv);
divider.setBackgroundResource(R.drawable.bg_trans_light_10);
netLayout.addView(divider);
netLayout.invalidate();
}
示例15: addAttachmentToInput
import android.widget.TextView; //导入方法依赖的package包/类
void addAttachmentToInput(@NonNull IAct_AInput pA_Customerly_Activity) {
pA_Customerly_Activity._Attachments.add(this);
TextView tv = new TextView(pA_Customerly_Activity);
tv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.io_customerly__ld_chat_attachment, 0, 0, 0);
int _5dp = IU_Utils.px(5);
tv.setCompoundDrawablePadding(_5dp);
tv.setPadding(_5dp, 0, 0, 0);
tv.setTextColor(IU_Utils.getColorStateListFromResource(pA_Customerly_Activity.getResources(), R.color.io_customerly__textcolor_malibu_grey));
tv.setLines(1);
tv.setSingleLine();
tv.setEllipsize(TextUtils.TruncateAt.MIDDLE);
tv.setTypeface(Typeface.SANS_SERIF, Typeface.NORMAL);
tv.setText(this.name);
tv.setOnClickListener(textView -> new AlertDialog.Builder(pA_Customerly_Activity)
.setTitle(R.string.io_customerly__choose_a_file_to_attach)
.setMessage(pA_Customerly_Activity.getString(R.string.io_customerly__cancel_attachment, tv.getText()))
.setNegativeButton(R.string.io_customerly__cancel, null)
.setPositiveButton(R.string.io_customerly__remove, (dlg, which) -> {
ViewGroup vg = (ViewGroup)tv.getParent();
if(vg != null) {
vg.removeView(tv);
}
pA_Customerly_Activity._Attachments.remove(this);
})
.setCancelable(true)
.show());
pA_Customerly_Activity.input_attachments.addView(tv);
}