List of usage examples for android.widget TextView setPadding
@Override public void setPadding(int left, int top, int right, int bottom)
From source file:com.spoiledmilk.ibikecph.favorites.FavoritesAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View view = inflater.inflate(getListRowLayout(), parent, false); TextView tv = (TextView) view.findViewById(R.id.textFavoriteName); String name = getItem(position).getName(); if (name.length() > 19) name = name.substring(0, 19) + "..."; tv.setText(name);// ww w. j a v a 2 s . com tv.setTypeface(IbikeApplication.getNormalFont()); tv.setTextColor(getTextColor()); ImageButton btnEdit = (ImageButton) view.findViewById(R.id.btnEdit); final FavoritesData fd = getItem(position); tv.setPadding(getPadding(fd), 0, 0, 0); btnEdit.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { fragment.onEditFavorite(fd); } }); final ImageView imgIcon = ((ImageView) view.findViewById(R.id.icon)); if (!isEditMode) { imgIcon.setImageResource(getIconResourceId(getItem(position))); btnEdit.setVisibility(View.GONE); } else { imgIcon.setImageResource(R.drawable.fav_reorder); btnEdit.setVisibility(View.VISIBLE); } return view; }
From source file:com.near.chimerarevo.fragments.ProductFragment.java
private void addRow(String key, String val, int i) { LinearLayout ll = new LinearLayout(getActivity()); ll.setOrientation(LinearLayout.HORIZONTAL); ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); if (i % 2 == 1) ll.setBackgroundColor(getResources().getColor(android.R.color.white)); TextView tv1 = new TextView(getActivity()); TextView tv2 = new TextView(getActivity()); tv1.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); tv2.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); tv1.setPadding(20, 10, 0, 10); tv2.setPadding(0, 10, 20, 10);//from w ww . ja v a 2 s .co m tv1.setTypeface(Typeface.createFromAsset(getActivity().getAssets(), "roboto_condensed.ttf")); tv2.setTypeface(Typeface.createFromAsset(getActivity().getAssets(), "roboto_light.ttf")); tv1.setTextSize(16); tv2.setTextSize(15); tv1.setText(key); tv2.setText(val); ll.addView(tv1); ll.addView(tv2); lay.addView(ll); }
From source file:com.ns.developer.tagview.widget.TagCloudLinkView.java
/** * tag draw/*from w w w . jav a 2 s. c o m*/ */ public void drawTags() { if (!mInitialized) { return; } // clear all tag removeAllViews(); // layout padding left & layout padding right float total = getPaddingLeft() + getPaddingRight(); // ???index int index = 1; // ? int pindex = index; // List Index int listIndex = 0; for (String item : mTags) { final int position = listIndex; final String tag = item; // inflate tag layout View tagLayout = (View) mInflater.inflate(R.layout.tag, null); tagLayout.setId(index); // tagLayout.setBackgroundColor(mTagLayoutColor); // tag text TextView tagView = (TextView) tagLayout.findViewById(R.id.tag_txt); tagView.setText(tag); tagView.setPadding(INNER_VIEW_PADDING, INNER_VIEW_PADDING, INNER_VIEW_PADDING, INNER_VIEW_PADDING); tagView.setTextColor(mTagTextColor); tagView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mSelectListener != null) { mSelectListener.onTagSelected(tag, position); } } }); // calculateof tag layout width float tagWidth = tagView.getPaint().measureText(tag) + INNER_VIEW_PADDING * 2; // tagView padding (left & right) // deletable text TextView deletableView = (TextView) tagLayout.findViewById(R.id.delete_txt); if (mIsDeletable) { deletableView.setVisibility(View.VISIBLE); deletableView.setText(DEFAULT_DELETABLE_STRING); deletableView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mDeleteListener != null) { String targetTag = tag; TagCloudLinkView.this.remove(position); mDeleteListener.onTagDeleted(targetTag, position); } } }); tagWidth += deletableView.getPaint().measureText(DEFAULT_DELETABLE_STRING) + INNER_VIEW_PADDING * 2; // deletableView Padding (left & right) } else { deletableView.setVisibility(View.GONE); } LayoutParams tagParams = new LayoutParams(HEIGHT_WC, HEIGHT_WC); tagParams.setMargins(0, 0, 0, 0); if (mWidth <= total + tagWidth + LAYOUT_WIDTH_OFFSET) { tagParams.addRule(RelativeLayout.BELOW, pindex); tagParams.topMargin = TAG_LAYOUT_TOP_MERGIN; // initialize total param (layout padding left & layout padding right) total = getPaddingLeft() + getPaddingRight(); pindex = index; } else { tagParams.addRule(RelativeLayout.ALIGN_TOP, pindex); tagParams.addRule(RelativeLayout.RIGHT_OF, index - 1); if (index > 1) { tagParams.leftMargin = TAG_LAYOUT_LEFT_MERGIN; total += TAG_LAYOUT_LEFT_MERGIN; } } total += tagWidth; addView(tagLayout, tagParams); index++; listIndex++; } LayoutParams tagParams = new LayoutParams(HEIGHT_WC, HEIGHT_WC); tagParams.setMargins(0, 0, 0, 0); if (isAutoCompleteMode || !mIsDeletable) { return; } int tagWidth = 50; //25dp if (mWidth <= total + tagWidth + LAYOUT_WIDTH_OFFSET) { tagParams.addRule(RelativeLayout.BELOW, pindex); tagParams.topMargin = TAG_LAYOUT_TOP_MERGIN; // initialize total param (layout padding left & layout padding right) total = getPaddingLeft() + getPaddingRight(); pindex = index; } else { tagParams.addRule(RelativeLayout.ALIGN_TOP, pindex); tagParams.addRule(RelativeLayout.RIGHT_OF, index - 1); if (index > 1) { tagParams.leftMargin = TAG_LAYOUT_LEFT_MERGIN; total += TAG_LAYOUT_LEFT_MERGIN; } } total += tagWidth; View tagLayout = (View) mInflater.inflate(R.layout.tag, null); addView(tagLayout, tagParams); tagLayout.findViewById(R.id.add_image_view).setVisibility(VISIBLE); tagLayout.findViewById(R.id.tag_txt).setVisibility(GONE); tagLayout.setClickable(true); tagLayout.setFocusable(true); tagLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (mAddTagListener != null) { mAddTagListener.onAddTag(); } } }); int transparentColor = ContextCompat.getColor(getContext(), android.R.color.transparent); tagLayout.setBackgroundColor(transparentColor); }
From source file:com.bionx.res.DashMainActivity.java
@SuppressWarnings("deprecation") @Override// w ww . ja va2s .c o m protected Dialog onCreateDialog(int id) { switch (id) { case 11: // Create our About Dialog TextView aboutMsg = new TextView(this); aboutMsg.setMovementMethod(LinkMovementMethod.getInstance()); aboutMsg.setPadding(30, 30, 30, 30); aboutMsg.setText(Html.fromHtml( "To view more information about the development of the Bionx Dashboard, Continue into the Information Center, If you don't care much for license and authors, click 'Proceed'.")); Builder builder = new AlertDialog.Builder(this); builder.setView(aboutMsg) .setTitle(Html.fromHtml("Dashboard <b><font color='" + getResources().getColor(R.color.holo_blue) + "'>Info</font></b>")) .setIcon(R.drawable.ic_launcher).setCancelable(true) .setPositiveButton("Information Drawer", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent dialog_intent = new Intent(getBaseContext(), InformationDrawer.class); startActivity(dialog_intent); } }).setNegativeButton("Proceed", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(getApplicationContext(), "Bionx Dashboard", Toast.LENGTH_LONG).show(); } }); return builder.create(); } return super.onCreateDialog(id); }
From source file:com.near.chimerarevo.fragments.ProductFragment.java
private void addTitle(String text) { TextView title = new TextView(getActivity()); title.setBackgroundColor(getResources().getColor(R.color.prod_title_color)); title.setTextColor(getResources().getColor(android.R.color.white)); title.setTypeface(Typeface.createFromAsset(getActivity().getAssets(), "roboto_light.ttf")); title.setTextSize(22);/*from w ww . ja va 2s .c o m*/ title.setPadding(15, 10, 15, 10); LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); title.setLayoutParams(params); title.setText(text); View div = new View(getActivity()); div.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 2)); div.setBackgroundColor(getResources().getColor(R.color.prod_title_color)); lay.addView(title); lay.addView(div); }
From source file:com.appodeal.test.layout.SlidingTabLayout.java
/** * 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)}.//ww w . j a va 2 s. c o m */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.honeywell.printer.indicator.TabPageIndicator.java
/** * //from www .j a va 2 s. c o m * * @param index tab */ public void showTabRedDotView(int index, int res) { if (mTabLayout != null) { final TextView msgCountView = (TextView) mTabLayout.findViewById(index + ID_OFFSET); if (msgCountView != null) { int paddingPixels = (int) getResources().getDimension(R.dimen.indicator_num_padding); msgCountView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); final LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); int badgeMarginLeft = 0; int badgeMarginBottom = 0; if (index < 2) { badgeMarginLeft = (int) getResources().getDimension(R.dimen.indicator_no_number_marginleft); badgeMarginBottom = (int) getResources().getDimension(R.dimen.indicator_no_number_marginbottom); } else { badgeMarginLeft = (int) getResources().getDimension(R.dimen.indicator_no_number_marginleft_2); badgeMarginBottom = (int) getResources() .getDimension(R.dimen.indicator_no_number_marginbottom_2); } params.gravity = Gravity.CENTER; params.setMargins(badgeMarginLeft, 0, 0, badgeMarginBottom); params.width = (int) getResources().getDimension(R.dimen.indicator_no_number_width); ; params.height = (int) getResources().getDimension(R.dimen.indicator_no_number_height); ; msgCountView.setBackgroundResource(res); msgCountView.setLayoutParams(params); msgCountView.setVisibility(View.VISIBLE); } } }
From source file:com.rachelgrau.rachel.health4theworldstroke.Activities.InfoActivity.java
public void addHeaderWithText(String text) { LinearLayout ll = (LinearLayout) findViewById(R.id.text_linear_layout); TextView textView = new TextView(this); textView.setTypeface(null, Typeface.BOLD); textView.setText(text);/* w w w .j a v a2s .c o m*/ textView.setPadding(40, 40, 40, 10); textView.setTextSize(20); textView.setBackgroundColor(Color.WHITE); ll.addView(textView); }
From source file:mobisocial.musubi.objects.FileObj.java
@Override public View createView(Context context, ViewGroup frame) { LinearLayout container = new LinearLayout(context); container.setLayoutParams(CommonLayouts.FULL_WIDTH); container.setOrientation(LinearLayout.HORIZONTAL); container.setGravity(Gravity.CENTER); ImageView imageView = new ImageView(context); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); TextView valueTV = new TextView(context); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.BOTTOM | Gravity.LEFT); valueTV.setPadding(4, 0, 0, 0); container.addView(imageView);//from w w w. j av a2s . c o m container.addView(valueTV); return container; }
From source file:com.example.drugsformarinemammals.ViewPager_Pinnipeds.java
private void displayMessage(String messageTitle, String message) { AlertDialog.Builder myalert = new AlertDialog.Builder(this); TextView title = new TextView(this); title.setTypeface(Typeface.SANS_SERIF); title.setTextSize(20);/*from w w w. java 2 s.com*/ title.setTextColor(getResources().getColor(R.color.blue)); title.setPadding(8, 8, 8, 8); title.setText(""); title.setGravity(Gravity.CENTER_VERTICAL); LinearLayout layout = new LinearLayout(this); TextView text = new TextView(this); text.setTypeface(Typeface.SANS_SERIF); text.setTextSize(20); text.setPadding(10, 10, 10, 10); text.setText(message); layout.addView(text); myalert.setView(layout); myalert.setCustomTitle(title); myalert.setCancelable(true); myalert.show(); }