Java Code Examples for android.widget.TextView#setWidth()
The following examples show how to use
android.widget.TextView#setWidth() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainViewer.java From GNSS_Compare with Apache License 2.0 | 6 votes |
private void initializeTextView( TextView view, GridLayout layout, int columnId){ layout.addView(view); GridLayout.LayoutParams param = new GridLayout.LayoutParams(); param.height = GridLayout.LayoutParams.WRAP_CONTENT; param.width = GridLayout.LayoutParams.WRAP_CONTENT; param.rightMargin = 5; param.topMargin = 5; view.setTextSize(11); view.setWidth(TEXT_FIELD_WIDTH[columnId]); view.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); param.setGravity(Gravity.CENTER); param.columnSpec = GridLayout.spec(columnId); param.rowSpec = GridLayout.spec(rowId); view.setLayoutParams (param); }
Example 2
Source File: RobotItemAdapter.java From imsdk-android with MIT License | 6 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { LinearLayout lin = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.atom_ui_item_robot_tab, parent, false); final TextView textView = (TextView) lin.findViewById(R.id.content); final View line = lin.findViewById(R.id.line); Action item = (Action) getItem(position); if (position == 0) { line.setVisibility(View.INVISIBLE); } textView.setText(item.mainaction); textView.setTextSize(16); textView.setWidth(parent.getWidth() / getCount()); textView.setFocusable(true); textView.setClickable(true); if (item.subactions != null && item.subactions.size() > 0) { Drawable drawable = context.getResources().getDrawable(R.drawable.atom_ui_has_child_action); if (drawable != null) { drawable.setBounds(10, 0, 20, 20); textView.setCompoundDrawables(drawable, null, null, null); } } return lin; }
Example 3
Source File: CustomPlaybackOverlayFragment.java From jellyfin-androidtv with GNU General Public License v2.0 | 6 votes |
private void fillTimeLine(int hours) { mCurrentGuideStart = Calendar.getInstance(); mCurrentGuideStart.set(Calendar.MINUTE, mCurrentGuideStart.get(Calendar.MINUTE) >= 30 ? 30 : 0); mCurrentGuideStart.set(Calendar.SECOND, 0); mCurrentGuideStart.set(Calendar.MILLISECOND, 0); mCurrentLocalGuideStart = mCurrentGuideStart.getTimeInMillis(); mDisplayDate.setText(TimeUtils.getFriendlyDate(mCurrentGuideStart.getTime())); Calendar current = (Calendar) mCurrentGuideStart.clone(); mCurrentGuideEnd = (Calendar) mCurrentGuideStart.clone(); int oneHour = 60 * PIXELS_PER_MINUTE; int halfHour = 30 * PIXELS_PER_MINUTE; int interval = current.get(Calendar.MINUTE) >= 30 ? 30 : 60; mCurrentGuideEnd.add(Calendar.HOUR, hours); mCurrentLocalGuideEnd = mCurrentGuideEnd.getTimeInMillis(); mTimeline.removeAllViews(); while (current.before(mCurrentGuideEnd)) { TextView time = new TextView(mActivity); time.setText(android.text.format.DateFormat.getTimeFormat(mActivity).format(current.getTime())); time.setWidth(interval == 30 ? halfHour : oneHour); mTimeline.addView(time); current.add(Calendar.MINUTE, interval); //after first one, we always go on hours interval = 60; } }
Example 4
Source File: LiteSyllabusView.java From LiteSyllabusView with Apache License 2.0 | 6 votes |
private void setupSectionSidebar() { layoutSectionSidebar = new LinearLayout(mContext); layoutSectionSidebar.setOrientation(VERTICAL); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(mSectionSidebarWidth, ViewGroup.LayoutParams.MATCH_PARENT); layoutSectionSidebar.setLayoutParams(params); for (int i = 1; i <= mSectionNumber; ++i) { layoutSectionSidebar.addView(getHorizontalDividerView()); TextView tvSectionNumberTitle = new TextView(mContext); tvSectionNumberTitle.setWidth(mSectionSidebarWidth); tvSectionNumberTitle.setHeight(mSectionHeight); tvSectionNumberTitle.setText("" + i); tvSectionNumberTitle.setTextSize(SECTION_SIDEBAR_TEXT_SIZE); tvSectionNumberTitle.setTextColor(ContextCompat.getColor(mContext, R.color.textTitle)); tvSectionNumberTitle.setGravity(Gravity.CENTER); tvSectionNumberTitle.setTypeface(mTitleTypeface); layoutSectionSidebar.addView(tvSectionNumberTitle); } layoutSectionSidebar.setBackgroundColor(ContextCompat.getColor(mContext, R.color.bgSectionSidbar)); }
Example 5
Source File: ScheduleView.java From SmallGdufe-Android with GNU General Public License v3.0 | 6 votes |
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; }
Example 6
Source File: StringPresenter.java From VCL-Android with Apache License 2.0 | 5 votes |
public void onBindViewHolder(ViewHolder viewHolder, Object item) { Resources res = viewHolder.view.getContext().getResources(); TextView tv = (TextView) viewHolder.view; tv.setText(item.toString()); if (res.getString(R.string.preferences).equals(item.toString())) { tv.setBackground(res.getDrawable(R.drawable.ic_menu_preferences_big)); } tv.setHeight(res.getDimensionPixelSize(R.dimen.grid_card_thumb_height)); tv.setWidth(res.getDimensionPixelSize(R.dimen.grid_card_thumb_width)); }
Example 7
Source File: OrreryInfo.java From AnimationApiDemos with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LinearLayout result = new LinearLayout(getActivity()); result.setOrientation(LinearLayout.VERTICAL); result.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); TextView info = new TextView(getActivity()); info.setText("Humans live on Earth, and Moon Mice live on the Moon. Nothing lives on the Sun, because it's a little too hot."); info.setWidth(200); info.setTextColor(Color.RED); result.addView(info); return result; }
Example 8
Source File: SlidingTabLayout.java From shift with Apache License 2.0 | 5 votes |
/** * 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)}. */ 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); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } final float density = getResources().getDisplayMetrics().density; int padding = (int) (TAB_VIEW_PADDING_DIPS * density); textView.setPadding(padding, padding, padding, padding); textView.setWidth(widthPixels / 3); return textView; }
Example 9
Source File: LiteSyllabusView.java From LiteSyllabusView with Apache License 2.0 | 5 votes |
private void setupWeekdayHeader() { layoutWeekdayHeader = new LinearLayout(mContext); layoutWeekdayHeader.setOrientation(HORIZONTAL); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mWeekdayHeaderHeight); layoutWeekdayHeader.setLayoutParams(params); TextView tvEmptyCellOnTopAndLeft = new TextView(mContext); tvEmptyCellOnTopAndLeft.setWidth(mSectionSidebarWidth); tvEmptyCellOnTopAndLeft.setHeight(mWeekdayHeaderHeight); tvEmptyCellOnTopAndLeft.setText("\\"); tvEmptyCellOnTopAndLeft.setTextSize(WEEKDAY_TITLE_TEXT_SIZE); tvEmptyCellOnTopAndLeft.setTextColor(ContextCompat.getColor(mContext, R.color.textTitle)); tvEmptyCellOnTopAndLeft.setGravity(Gravity.CENTER); tvEmptyCellOnTopAndLeft.setTypeface(mTitleTypeface); layoutWeekdayHeader.addView(tvEmptyCellOnTopAndLeft); for (int i = 0; i < mWeekdayNumber; ++i) { layoutWeekdayHeader.addView(getVerticalDividerView()); TextView tvWeekdayTitle = new TextView(mContext); tvWeekdayTitle.setWidth(mSectionWidth); tvWeekdayTitle.setHeight(mWeekdayHeaderHeight); tvWeekdayTitle.setText(WEEKDAY_TITLES[i]); tvWeekdayTitle.setTextSize(WEEKDAY_TITLE_TEXT_SIZE); tvWeekdayTitle.setTextColor(ContextCompat.getColor(mContext, R.color.textTitle)); tvWeekdayTitle.setGravity(Gravity.CENTER); tvWeekdayTitle.setTypeface(mTitleTypeface); layoutWeekdayHeader.addView(tvWeekdayTitle); } layoutWeekdayHeader.setBackgroundColor(ContextCompat.getColor(mContext, R.color.bgWeekdayHeader)); }
Example 10
Source File: CourseView.java From LiteSyllabusView with Apache License 2.0 | 5 votes |
private void setNote() { tvNote = new TextView(mContext); tvNote.setWidth(mSectionWidth); tvNote.setText("[" + mData.getNote() + "]"); tvNote.setTextSize(mNoteTextSize); tvNote.setTextColor(ContextCompat.getColor(mContext, R.color.textCourse)); addView(tvNote); }
Example 11
Source File: CourseView.java From LiteSyllabusView with Apache License 2.0 | 5 votes |
private void setPosition() { tvPosition = new TextView(mContext); tvPosition.setWidth(mSectionWidth); tvPosition.setText("@" + mData.getPosition()); tvPosition.setTextSize(mPositionTextSize); tvPosition.setTextColor(ContextCompat.getColor(mContext, R.color.textCourse)); addView(tvPosition); }
Example 12
Source File: CourseView.java From LiteSyllabusView with Apache License 2.0 | 5 votes |
private void setName() { tvName = new TextView(mContext); tvName.setWidth(mSectionWidth); tvName.setText(mData.getName()); tvName.setTextSize(mNameTextSize); tvName.setTextColor(ContextCompat.getColor(mContext, R.color.textCourse)); tvName.setTypeface(Typeface.DEFAULT_BOLD); addView(tvName); }
Example 13
Source File: Game.java From Simple-Solitaire with GNU General Public License v3.0 | 5 votes |
/** * Create a textView and add it to the given layout (game content). Used to add custom texts * to a game. This also sets the text apperance to AppCompat and the gravity to center. * The width and height is also measured, so you can use it directly. * * @param width The width to apply to the * @param layout he textView will be added to this layout * @param context Context to create view */ protected void addTextViews(int count, int width, RelativeLayout layout, Context context) { for (int i = 0; i < count; i++) { TextView textView = new TextView(context); textView.setWidth(width); TextViewCompat.setTextAppearance(textView, R.style.TextAppearance_AppCompat); textView.setGravity(Gravity.CENTER); textView.setTextColor(textViewColor); layout.addView(textView); textView.measure(0, 0); textViews.add(textView); } }
Example 14
Source File: ScheduleView.java From SmallGdufe-Android with GNU General Public License v3.0 | 5 votes |
/** * 获取单个课表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; }
Example 15
Source File: ScheduleView.java From SmallGdufe-Android with GNU General Public License v3.0 | 5 votes |
/** * 竖向分界线 * * @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; }
Example 16
Source File: ScheduleView.java From SmallGdufe-Android with GNU General Public License v3.0 | 5 votes |
/** * 横的分界线 * * @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; }
Example 17
Source File: LiveTvGuideActivity.java From jellyfin-androidtv with GNU General Public License v2.0 | 5 votes |
private void fillTimeLine(long start, int hours) { mCurrentGuideStart = Calendar.getInstance(); mCurrentGuideStart.setTime(new Date(start)); mCurrentGuideStart.set(Calendar.MINUTE, mCurrentGuideStart.get(Calendar.MINUTE) >= 30 ? 30 : 0); mCurrentGuideStart.set(Calendar.SECOND, 0); mCurrentGuideStart.set(Calendar.MILLISECOND, 0); mCurrentLocalGuideStart = mCurrentGuideStart.getTimeInMillis(); mDisplayDate.setText(TimeUtils.getFriendlyDate(mCurrentGuideStart.getTime())); Calendar current = (Calendar) mCurrentGuideStart.clone(); mCurrentGuideEnd = (Calendar) mCurrentGuideStart.clone(); int oneHour = 60 * PIXELS_PER_MINUTE; int halfHour = 30 * PIXELS_PER_MINUTE; int interval = current.get(Calendar.MINUTE) >= 30 ? 30 : 60; mCurrentGuideEnd.add(Calendar.HOUR, hours); mCurrentLocalGuideEnd = mCurrentGuideEnd.getTimeInMillis(); mTimeline.removeAllViews(); while (current.before(mCurrentGuideEnd)) { TextView time = new TextView(this); time.setText(android.text.format.DateFormat.getTimeFormat(this).format(current.getTime())); time.setWidth(interval == 30 ? halfHour : oneHour); mTimeline.addView(time); current.add(Calendar.MINUTE, interval); //after first one, we always go on hours interval = 60; } }
Example 18
Source File: SqliteTableActivity.java From AndroidSamples with Apache License 2.0 | 4 votes |
private void showData() { mList.clear(); Cursor cursor = db.query("usertable", null, null, null, null, null, null); //判断游标是否为空 if (cursor.moveToFirst()) { int x = cursor.getCount(); //遍历游标 do { List<String> list = new ArrayList<>(); //获得ID int id = cursor.getInt(0); String name = cursor.getString(1); String red = cursor.getString(2); String green = cursor.getString(3); String yellow = cursor.getString(4); Log.e("test", "showData: " + id); Log.e("test", "x: " + x); list.add(id + ""); list.add(name); list.add(red); list.add(green); list.add(yellow); mList.add(list); } while (cursor.moveToNext()); cursor.close(); Log.e("test", mList.toString()); //清除表格所有行 mTable1.removeAllViews(); //全部列自动填充空白处 mTable1.setStretchAllColumns(true); // 4列x行 for (int i = 0; i < x; i++) { TableRow tableRow = new TableRow(SqliteTableActivity.this); for (int j = 0; j < 4; j++) { TextView tv = new TextView(SqliteTableActivity.this); tv.setText(mList.get(i).get(j + 1) + ""); tv.setBackgroundResource(R.drawable.table_bg); tv.setPadding(0, 5, 0, 5); tv.setGravity(Gravity.CENTER); tv.setWidth(1); tableRow.addView(tv); } mTable1.addView(tableRow, new TableLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1)); } } }
Example 19
Source File: RMBTResultPagerAdapter.java From open-rmbt with Apache License 2.0 | 4 votes |
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(); }
Example 20
Source File: PanelListAdapter.java From SmartChart with Apache License 2.0 | 4 votes |
/** * 初始化横向表头的布局,必须在所有的布局都载入完之后才能调用 * <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); } } }