本文整理汇总了Java中android.widget.TextView.setWidth方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.setWidth方法的具体用法?Java TextView.setWidth怎么用?Java TextView.setWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.setWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initHistoryData
import android.widget.TextView; //导入方法依赖的package包/类
private void initHistoryData(List<String> allNames) {
int padding = (int) (DensityUtil.dip2px(10f) * DensityUtil.getBaseScale(getContext()));
TagAdapter adapter = new TagAdapter<String>(allNames) {
@Override
public View getView(FlowLayout parent, int position, String s) {
TextView textView = new TextView(getContext());
textView.setLayoutParams(new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
textView.setWidth((int) (DensityUtil.dip2px(80f) * DensityUtil.getBaseScale(getContext())));
textView.setLines(1);
textView.setGravity(Gravity.CENTER);
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setPadding(padding, padding, padding, padding);
textView.setText(s);
return textView;
}
};
mBinding.flowLayoutHistory.setAdapter(adapter);
mBinding.flowLayoutHistory.setOnTagClickListener((view, position, parent) -> {
String item = (String) adapter.getItem(position);
return false;
});
}
示例2: inflateTextView
import android.widget.TextView; //导入方法依赖的package包/类
private TextView inflateTextView() {
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius(8);
shape.setColor(0xff000000 | mRandom.nextInt(0x00ffffff));
TextView textView = new TextView(this);
textView.setGravity(Gravity.CENTER);
textView.setTextColor(Color.WHITE);
textView.setWidth(150 + mRandom.nextInt(3) * 50);
textView.setHeight(150 + mRandom.nextInt(3) * 50);
textView.setTextSize(32);
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
textView.setBackgroundDrawable(shape);
} else {
textView.setBackground(shape);
}
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
mList.removeViewWithAnimation(view);
}
});
textView.setText(String.format(Locale.JAPAN, "%1$02d", mCounter++));
return textView;
}
示例3: addStartView
import android.widget.TextView; //导入方法依赖的package包/类
private View addStartView(int startnum, final int week, final int start) {
LinearLayout mStartView = new LinearLayout(getContext());
mStartView.setOrientation(VERTICAL);
for (int i = 1; i < startnum; i++) {
TextView mTime = new TextView(getContext());
mTime.setGravity(Gravity.CENTER);
mTime.setHeight(dip2px(TimeTableHeight));
mTime.setWidth(dip2px(TimeTableHeight));
mStartView.addView(mTime);
mStartView.addView(getWeekTransverseLine());
//这里可以处理空白处点击添加课表
final int finalI = i;
mTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Toast.makeText(getContext(), "星期" + week + "第" + (start + num) + "节", Toast.LENGTH_SHORT).show();
//TODO 添加课程
mClickListener.onClickScheduleAdd(week,start+ finalI);
}
});
}
return mStartView;
}
示例4: getViewForTab
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public View getViewForTab(int position, View convertView, ViewGroup container) {
if (convertView == null) {
convertView = LayoutInflater.from(container.getContext()).inflate(R.layout.tab_top, container, false);
}
TextView textView = (TextView) convertView;
textView.setText(mClassifyList.get(position).getClassify_name());
int witdh = getTextWidth(textView);
int padding = DisplayUtil.dipToPix(container.getContext(), 8);
//因为wrap的布局 字体大小变化会导致textView大小变化产生抖动,这里通过设置textView宽度就避免抖动现象
//1.3f是根据上面字体大小变化的倍数1.3f设置
textView.setWidth((int) (witdh * 1.3f) + padding);
return convertView;
}
示例5: MeasureString
import android.widget.TextView; //导入方法依赖的package包/类
public static Point MeasureString(Context context, String text, float fontSize, int widthMeasureSpec, int heightMeasureSpec) {
int width = 0;
int height = 0;
if (null == context || null == text || text.isEmpty() || 0 == fontSize) {
return null;
}
TextView tv = new TextView(context);
tv.setText(text);// 待测文本
tv.setTextSize(fontSize);// 字体
if (ViewGroup.LayoutParams.WRAP_CONTENT != widthMeasureSpec && ViewGroup.LayoutParams.MATCH_PARENT != widthMeasureSpec) {
tv.setWidth(widthMeasureSpec);// 如果设置了宽度,字符串的宽度则为所设置的宽度
}
if (ViewGroup.LayoutParams.WRAP_CONTENT != heightMeasureSpec && ViewGroup.LayoutParams.MATCH_PARENT != heightMeasureSpec) {
tv.setHeight(heightMeasureSpec);
}
tv.setSingleLine(false);// 多行
tv.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
width = tv.getMeasuredWidth();
height = tv.getMeasuredHeight();
Point point = new Point();
point.x = width;
point.y = height;
return point;
}
示例6: setScale
import android.widget.TextView; //导入方法依赖的package包/类
public void setScale(float scale){
if(this.scale != scale){
this.scale = scale;
int width;
TextView textView;
for (int i = 0;i < mTextViewList.size();i++){
textView = mTextViewList.get(i);
width = textView.getWidth();
textView.setWidth((int) (width * (1 + scale)));
widthList.set(i, (int) (width * (1 + scale)));
}
}
}
示例7: 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();
}
示例8: getWeekTransverseLine
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 横的分界线
*
* @return
*/
private View getWeekTransverseLine() {
TextView mWeekline = new TextView(getContext());
mWeekline.setBackgroundColor(getResources().getColor(R.color.view_line));
mWeekline.setHeight(TimeTableLineHeight);
mWeekline.setWidth(LayoutParams.FILL_PARENT);
return mWeekline;
}
示例9: getWeekVerticalLine
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 竖向分界线
*
* @return
*/
private View getWeekVerticalLine() {
TextView mWeekline = new TextView(getContext());
mWeekline.setBackgroundColor(getResources().getColor(R.color.view_line));
mWeekline.setHeight(dip2px(TimeTableWeekNameHeight));
mWeekline.setWidth((TimeTableLineHeight));
return mWeekline;
}
示例10: getMode
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 获取单个课表View
*
* @param model 数据类型
* @return
*/
@SuppressWarnings("deprecation")
private View getMode(final Schedule model) {
LinearLayout mScheduleView = new LinearLayout(getContext());
mScheduleView.setOrientation(VERTICAL);
TextView mTimeTableNameView = new TextView(getContext());
int num = model.getEndSec() - model.getStartSec();
mTimeTableNameView.setHeight(dip2px((num + 1) * TimeTableHeight) + num * 2);
mTimeTableNameView.setTextColor(getContext().getResources().getColor(
android.R.color.white));
mTimeTableNameView.setWidth(dip2px(50));
mTimeTableNameView.setTextSize(CourseTextSize);
mTimeTableNameView.setGravity(Gravity.CENTER);
mTimeTableNameView.setText(model.getName() + "\n" + model.getLocation());
mScheduleView.addView(mTimeTableNameView);
mScheduleView.addView(getWeekTransverseLine());
mScheduleView.setBackgroundDrawable(getContext().getResources()
.getDrawable(colors[getColorNum(model.getName())]));
if(mCurrentWeek != FileUtils.SP_WEEK_NOT_SET && !CalcUtils.isCurrentWeek(model.getPeriod(), mCurrentWeek)){
mScheduleView.setBackgroundDrawable(getContext().getResources()
.getDrawable(notGocolors));
// mTimeTableNameView.setTextColor(getContext().getResources().getColor(
// android.R.color.darker_gray));
}
mScheduleView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Toast.makeText(getContext(), model.getName() + "\n" + model.getLocation()+"\n" +model.getPeriod()+"\n"+ model.getTeacher(), Toast.LENGTH_SHORT).show();
//TODO 编辑课程
mClickListener.onClickScheduleEdit(model);
}
});
return mScheduleView;
}
示例11: setClearingLayoutSizes
import android.widget.TextView; //导入方法依赖的package包/类
public void setClearingLayoutSizes(View rootView, Context context) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
float dpHeight = displayMetrics.heightPixels / displayMetrics.density;
float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
dpHeight -= addClearingButton.getHeight();
dpHeight /= 9;
dpWidth /= 7;
int finalValue = (int) Math.min(dpHeight, dpWidth);
TableLayout table = rootView.findViewById(R.id.clearingGrid);
final int childcount = table.getChildCount();
for (int i = 0; i < childcount; i++) {
TableRow row = (TableRow) table.getChildAt(i);
final int cellCount = row.getChildCount();
for (int j = 0; j < cellCount; j++) {
TextView cell = (TextView) row.getChildAt(j);
cell.setHeight(finalValue);
cell.setWidth(finalValue);
}
}
}
示例12: onBindViewHolder
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(MyHolder holder, int position) {
holder.tableLayout.removeAllViews();
holder.tableLayout.setTag(position);
holder.tableRow.removeAllViews();
NewColumnField newColumnField = mDates.get(position);
TextView textView = null;
for (int i = 0;i<mTitles.length;i++){
switch (i){
case 0:
textView = new CustomImage(mContext,false,null);
textView.setText(newColumnField.getFieldName());
break;
case 1:
textView = new CustomImage(mContext,false,null);
textView.setText(newColumnField.getFieldType());
break;
case 2:
textView = new CustomImage(mContext,newColumnField.isCheck(),null);
break;
case 3:
textView = new CustomImage(mContext,newColumnField.isNotNull(),null);
break;
case 4:
textView = new CustomImage(mContext,newColumnField.isUnique(),null);
break;
case 5:
textView = new CustomImage(mContext,newColumnField.isDefaultKey(),null);
break;
case 6:
textView = new CustomImage(mContext,newColumnField.isForeignKey(),null);
break;
case 7:
textView = new CustomImage(mContext,false,null);
textView.setText(newColumnField.getDefaultValue());
break;
case 8:
textView = new CustomImage(mContext,newColumnField.isPrimaryKey(),null);
break;
case 9:
textView = new CustomImage(mContext,newColumnField.isAutoIncrement(),null);
break;
case 10:
textView = new CustomImage(mContext,false,null);
textView.setText(newColumnField.getFkTable());
break;
case 11:
textView = new CustomImage(mContext,false,null);
textView.setText(newColumnField.getFkField());
break;
}
textView.setGravity(Gravity.CENTER_VERTICAL);
textView.setSingleLine(true);
textView.setTextColor(mContext.getResources().getColor(R.color.table_text_color));
if( (i>0 && i<= 5) || i>9){
textView.setWidth(FeViewUtils.dpToPx(85));
}else {
textView.setWidth(FeViewUtils.dpToPx(120));
}
textView.setPadding(25, 10, 25, 10);
holder.tableRow.addView(textView);
}
if (position == mClickPosition) {
holder.tableLayout.setBackgroundColor(mContext.getResources().getColor(R.color.blue));
} else {
holder.tableLayout.setBackgroundColor(mContext.getResources().getColor(android.R.color.transparent));
}
ViewGroup viewGroup = (ViewGroup) holder.tableRow.getParent();
if (viewGroup != null) {
viewGroup.removeAllViews();
}
holder.tableLayout.addView(holder.tableRow);
}
示例13: initRowLayout
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 初始化横向表头的布局,必须在所有的布局都载入完之后才能调用
* <p>
* must be called in pl_root.post();
*/
private void initRowLayout() {
if (rowDataList == null) {
Log.e("PanelList", "custom Row data list is strongly recommended! Call setRowDataList(List<String> rowDataList) in your panel adapter");
}
int rowCount = ll_contentItem.getChildCount();
List<String> rowDataList1 = getRowDataList(rowCount);
//分隔线的设置,如果content的item设置了分割线,那row使用相同的分割线,除非单独给row设置了分割线
ll_row.setBackgroundColor(Color.parseColor(rowColor));
if (rowDivider == null) {
ll_row.setDividerDrawable(ll_contentItem.getDividerDrawable());
} else {
ll_row.setDividerDrawable(rowDivider);
}
// 获得row一共有多少个item,然后使用循环往里面添加对应个数个TextView(简单粗暴)
for (int i = 0; i < rowCount; i++) {
View contentItem = ll_contentItem.getChildAt(i);// 获得item的item,以便获取宽度
TextView rowItem = new TextView(context);
rowItem.setText(rowDataList1.get(i));//设置文字
Paint rowPaint=rowItem.getPaint();
rowPaint.setFakeBoldText(false);
rowPaint.setColor(context.getResources().getColor(R.color.color_646464));
rowPaint.setTextSize(CommonUtils.dp2px(context,15));
rowItem.setWidth(contentItem.getWidth()-2);//设置宽度
rowItem.setHeight(titleHeight);//设置高度
rowItem.setGravity(Gravity.CENTER);
TextView line=new TextView(context);
ll_row.addView(rowItem);
if (i<rowCount-1){
line.setBackgroundColor(Color.WHITE);
line.setWidth(2);
line.setHeight(titleHeight);
ll_row.addView(line);
}
}
}
示例14: getView
import android.widget.TextView; //导入方法依赖的package包/类
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
final Map<String, String> data = contentList.get(position);
ViewHolder viewHolder;
if (convertView == null) {
viewHolder=new ViewHolder();
convertView = LayoutInflater.from(parent.getContext()).inflate(resourceId, parent, false);
viewHolder.linearLayout = (LinearLayout) convertView.findViewById(R.id.linear_root);
int textWeight=CommonUtils.dp2px(context,itemHeight);
for (int i=0;i<data.size();i++){
TextView item = new TextView(context);
item.setWidth(textWeight);//设置宽度
item.setSingleLine();
item.setGravity(Gravity.CENTER);
item.setTextSize(15);
item.setTextColor(context.getResources().getColor(R.color.color_323232));
item.setPadding(5,5,5,5);
viewHolder.linearLayout.addView(item);
}
convertView.setTag(viewHolder);
}else{
viewHolder= (ViewHolder) convertView.getTag();
}
for (int i=0;i<data.size();i++){
((TextView)viewHolder.linearLayout.getChildAt(i)).setText(data.get(i+1+""));
}
if (lv_content.isItemChecked(position)){
convertView.setBackgroundColor(context.getResources().getColor(R.color.color_FBE382));
} else {
convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
}
if (position%2==0){
convertView.setBackgroundColor(context.getResources().getColor(R.color.color_f6f6f6));
}else{
convertView.setBackgroundColor(Color.WHITE);
}
return convertView;
}
示例15: onCreateView
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
int index = getArguments().getInt("INDEX");
View v = inflater.inflate(R.layout.view_matrix_frag, container, false);
CardView cardView = (CardView) v.findViewById(R.id.DynamicCardView);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
String string = sharedPreferences.getString("ELEVATE_AMOUNT", "4");
String string2 = sharedPreferences.getString("CARD_CHANGE_KEY", "#bdbdbd");
cardView.setCardElevation(Integer.parseInt(string));
cardView.setCardBackgroundColor(Color.parseColor(string2));
CardView.LayoutParams params1 = new CardView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
GridLayout gridLayout = new GridLayout(getContext());
gridLayout.setRowCount(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow());
gridLayout.setColumnCount(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol());
for (int i = 0; i < ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow(); i++) {
for (int j = 0; j < ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol(); j++) {
TextView textView = new TextView(getContext());
textView.setGravity(Gravity.CENTER);
textView.setText(SafeSubString(GetText(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetElementof(i, j)), getLength()));
textView.setWidth(CalculatedWidth(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol()));
textView.setTextSize(SizeReturner(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow(), ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetCol(),
PreferenceManager.getDefaultSharedPreferences(getContext()).
getBoolean("EXTRA_SMALL_FONT", false)));
textView.setHeight(CalculatedHeight(((GlobalValues) getActivity().getApplication()).GetCompleteList().get(index).GetRow()));
GridLayout.Spec Row = GridLayout.spec(i, 1);
GridLayout.Spec Col = GridLayout.spec(j, 1);
GridLayout.LayoutParams params = new GridLayout.LayoutParams(Row, Col);
gridLayout.addView(textView, params);
}
}
gridLayout.setLayoutParams(params1);
cardView.addView(gridLayout);
// Inflate the layout for this fragment
return v;
}