List of usage examples for android.widget TextView setPadding
@Override public void setPadding(int left, int top, int right, int bottom)
From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java
/** * SINGLE TEXT ROW/*from w w w. jav a2 s. c o m*/ * @param att * @param linear * @return */ public LinearLayout getSingleTextRow(Map<String, String> att, LinearLayout linear) { LinearLayout container_layout = new LinearLayout(context); container_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo)); container_layout.setMinimumHeight(46); container_layout.setVerticalGravity(Gravity.CENTER); LinearLayout.LayoutParams value = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.5f); TextView tx = new TextView(context); tx.setText(att.get("title")); tx.setTextSize(11); tx.setTypeface(null, Typeface.BOLD); tx.setGravity(Gravity.LEFT); tx.setPadding(3, 0, 0, 2); tx.setTextColor(Color.rgb(66, 66, 66)); container_layout.addView(tx, value); LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.5f); TextView t2 = new TextView(context); t2.setText(att.get("value").equals("") ? " - " : att.get("value")); t2.setTextSize(11); t2.setGravity(Gravity.CENTER_HORIZONTAL); t2.setPadding(2, 0, 0, 2); t2.setTextColor(Color.rgb(66, 66, 66)); container_layout.addView(t2, value_params); linear.addView(container_layout); return linear; }
From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java
/** * DOUBLE IMAGE ROW// w w w. j ava 2 s . co m * @param att * @param linear * @return */ public LinearLayout getDoubleImageRow(Map<String, String> att, LinearLayout linear) { LinearLayout container_layout = new LinearLayout(context); container_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo)); container_layout.setMinimumHeight(46); container_layout.setVerticalGravity(Gravity.CENTER); LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.3f); TextView tx = new TextView(context); tx.setText(att.get("title")); tx.setTextSize(11); tx.setTypeface(null, Typeface.BOLD); tx.setGravity(Gravity.LEFT); tx.setPadding(3, 0, 0, 2); tx.setTextColor(Color.rgb(66, 66, 66)); container_layout.addView(tx, value_params); LinearLayout.LayoutParams value_one_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 46, 0.35f); ImageView img1 = new ImageView(context); String path = "it.redturtle.mobile.apparpav:drawable/" + FilenameUtils.removeExtension(att.get("value1")); img1.setImageResource(context.getResources().getIdentifier(path, null, null)); img1.setPadding(0, 3, 0, 3); container_layout.addView(img1, value_one_params); LinearLayout.LayoutParams value_two_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 46, 0.35f); ImageView img2 = new ImageView(context); path = "it.redturtle.mobile.apparpav:drawable/" + FilenameUtils.removeExtension(att.get("value2")); img2.setImageResource(context.getResources().getIdentifier(path, null, null)); img2.setPadding(0, 3, 0, 3); container_layout.addView(img2, value_two_params); linear.addView(container_layout); return linear; }
From source file:com.normalexception.app.rx8club.view.profile.ProfileViewArrayAdapter.java
public View getView(int position, View convertView, ViewGroup parent) { View vi = convertView;/* w w w. ja v a2s . c o m*/ if (vi == null) { vi = new TextView(sourceFragment.getActivity()); } TextView tv = (TextView) vi; final ProfileModel pm = data.get(position); String text = String.format("%s\n%s", pm.getName(), pm.getText()); SpannableString spanString = new SpannableString(text); spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, text.indexOf("\n"), 0); spanString.setSpan(new StyleSpan(Typeface.ITALIC), text.indexOf("\n") + 1, text.length(), 0); tv.setText(spanString); tv.setPadding(1, 10, 1, 10); tv.setBackgroundColor(Color.DKGRAY); tv.setTextColor(Color.WHITE); tv.setTextSize(10); tv.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Bundle args = new Bundle(); args.putString("link", pm.getLink()); args.putString("title", pm.getName()); FragmentUtils.fragmentTransaction(sourceFragment.getActivity(), ThreadFragment.newInstance(), false, true, args); } }); return vi; }
From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java
/** * DOUBLE TEXT ROW//from ww w . j a va2s. com * @param att * @param linear * @return */ public LinearLayout getDoubleTextRow(Map<String, String> att, LinearLayout linear) { LinearLayout container_layout = new LinearLayout(context); container_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo)); container_layout.setMinimumHeight(46); container_layout.setVerticalGravity(Gravity.CENTER); LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.3f); TextView tx = new TextView(context); tx.setText(att.get("title")); tx.setTextSize(11); tx.setTypeface(null, Typeface.BOLD); tx.setGravity(Gravity.LEFT); tx.setPadding(2, 0, 0, 2); tx.setTextColor(Color.rgb(66, 66, 66)); container_layout.addView(tx, value_params); LinearLayout.LayoutParams value_one_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.35f); TextView t1 = new TextView(context); t1.setText(att.get("value1").equals("") ? " - " : att.get("value1")); t1.setTextSize(11); t1.setGravity(Gravity.CENTER_HORIZONTAL); t1.setPadding(2, 0, 0, 2); t1.setTextColor(Color.rgb(66, 66, 66)); container_layout.addView(t1, value_one_params); LinearLayout.LayoutParams value_two_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.35f); TextView t2 = new TextView(context); t2.setTextSize(11); t2.setText(att.get("value2").equals("") ? " - " : att.get("value2")); t2.setGravity(Gravity.CENTER_HORIZONTAL); t2.setPadding(2, 0, 0, 2); t2.setTextColor(Color.rgb(66, 66, 66)); container_layout.addView(t2, value_two_params); linear.addView(container_layout); return linear; }
From source file:com.rachelgrau.rachel.health4theworldstroke.Activities.InfoActivity.java
public void addTextViewWithText(String text) { LinearLayout ll = (LinearLayout) findViewById(R.id.text_linear_layout); TextView secondPar = new TextView(this); secondPar.setText(text);// w w w . j a v a2s .c om secondPar.setPadding(40, 10, 40, 0); secondPar.setTextSize(14); secondPar.setBackgroundColor(Color.WHITE); ll.addView(secondPar); }
From source file:com.rachelgrau.rachel.health4theworldstroke.Activities.InfoActivity.java
public void addIndentedTextViewWithText(String text) { LinearLayout ll = (LinearLayout) findViewById(R.id.text_linear_layout); TextView secondPar = new TextView(this); secondPar.setText(text);/*from w w w .j av a 2 s.c om*/ secondPar.setPadding(65, 10, 40, 0); secondPar.setTextSize(14); secondPar.setBackgroundColor(Color.WHITE); ll.addView(secondPar); }
From source file:com.glanznig.beepme.view.ViewSampleFragment.java
private void populateFields() { if (sampleId != 0L) { Sample s = new SampleTable(getActivity().getApplicationContext()).getSampleWithTags(sampleId); TextView timestamp = (TextView) getView().findViewById(R.id.view_sample_timestamp); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); timestamp.setText(dateFormat.format(s.getTimestamp())); TextView title = (TextView) getView().findViewById(R.id.view_sample_title); if (s.getTitle() != null && s.getTitle().length() > 0) { title.setText(s.getTitle()); } else {//from ww w . ja v a2s . com title.setText(getString(R.string.sample_untitled)); } TextView description = (TextView) getView().findViewById(R.id.view_sample_description); if (s.getDescription() != null && s.getDescription().length() > 0) { description.setTextSize(14); description.setText(s.getDescription()); } else { description.setTextSize(12); // not editable any more if ((Calendar.getInstance().getTimeInMillis() - s.getTimestamp().getTime()) >= 24 * 60 * 60 * 1000) { description.setText(getString(R.string.sample_no_description)); } else { description.setText(getString(R.string.sample_no_description_editable)); } } boolean hasKeywordTags = false; FlowLayout keywordHolder = (FlowLayout) getView().findViewById(R.id.view_sample_keyword_container); keywordHolder.removeAllViews(); Iterator<Tag> i = s.getTags().iterator(); Tag tag = null; while (i.hasNext()) { tag = i.next(); if (tag.getVocabularyId() == 1) { TextView view = new TextView(getView().getContext()); view.setText(tag.getName()); final float scale = getResources().getDisplayMetrics().density; int textPaddingLeftRight = 6; int textPaddingTopBottom = 2; view.setPadding((int) (textPaddingLeftRight * scale + 0.5f), (int) (textPaddingTopBottom * scale + 0.5f), (int) (textPaddingLeftRight * scale + 0.5f), (int) (textPaddingTopBottom * scale + 0.5f)); view.setBackgroundColor(getResources().getColor(R.color.bg_keyword)); keywordHolder.addView(view); hasKeywordTags = true; } } TextView noKeywordsView = (TextView) getView().findViewById(R.id.view_sample_no_keywords); if (!hasKeywordTags) { keywordHolder.setVisibility(View.GONE); noKeywordsView.setVisibility(View.VISIBLE); // not editable any more (after 1 day) if ((Calendar.getInstance().getTimeInMillis() - s.getTimestamp().getTime()) >= 24 * 60 * 60 * 1000) { noKeywordsView.setText(getString(R.string.sample_no_keywords)); } else { noKeywordsView.setText(getString(R.string.sample_no_keywords_editable)); } } else { noKeywordsView.setVisibility(View.GONE); keywordHolder.setVisibility(View.VISIBLE); } photoView = (SamplePhotoView) getView().findViewById(R.id.view_sample_photo); photoView.setRights(false, false); // read only DisplayMetrics metrics = getView().getContext().getResources().getDisplayMetrics(); int thumbnailSize; if (!isLandscape()) { photoView.setFrameWidth(LayoutParams.MATCH_PARENT); thumbnailSize = (int) (metrics.widthPixels / metrics.density + 0.5f); } else { thumbnailSize = (int) (metrics.heightPixels / metrics.density + 0.5f); } String thumbnailUri = PhotoUtils.getThumbnailUri(s.getPhotoUri(), thumbnailSize); if (thumbnailUri != null) { File thumb = new File(thumbnailUri); if (thumb.exists()) { ImgLoadHandler handler = new ImgLoadHandler(photoView); PhotoUtils.getAsyncBitmap(getView().getContext(), thumbnailUri, handler); } else { Handler handler = new Handler(this); PhotoUtils.generateThumbnails(getView().getContext(), s.getPhotoUri(), handler); } } else { photoView.unsetPhoto(); } } }
From source file:de.gebatzens.sia.fragment.RemoteDataFragment.java
public void createMessage(ViewGroup l, String text, String button, View.OnClickListener onclick) { RelativeLayout r = new RelativeLayout(getActivity()); r.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); LinearLayout l2 = new LinearLayout(getActivity()); l2.setOrientation(LinearLayout.VERTICAL); RelativeLayout.LayoutParams layoutparams = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutparams.addRule(RelativeLayout.CENTER_VERTICAL); l2.setLayoutParams(layoutparams);//from w w w .ja v a 2s . c om l2.setGravity(Gravity.CENTER_HORIZONTAL); TextView tv = new TextView(getActivity()); LinearLayout.LayoutParams tvparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); tv.setLayoutParams(tvparams); tv.setText(text); tv.setTextSize(23); tv.setPadding(0, 0, 0, toPixels(15)); l2.addView(tv); if (button != null) { Button b = new Button(getActivity()); LinearLayout.LayoutParams bparams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); bparams.setMargins(toPixels(4), toPixels(0), toPixels(4), toPixels(4)); b.setLayoutParams(bparams); b.setId(R.id.reload_button); b.setText(button); b.setTextSize(23); b.setAllCaps(false); b.setTypeface(null, Typeface.NORMAL); b.setOnClickListener(onclick); l2.addView(b); } r.addView(l2); l.addView(r); }
From source file:com.woofer.activity.personHomeActivity.java
public void showTable() { TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT); layoutParams.gravity = Gravity.LEFT; layoutParams.leftMargin = 30;/* ww w . j a va 2s . c o m*/ layoutParams.bottomMargin = 10; layoutParams.topMargin = 10; for (int i = 0; i < 30; i++) { TableRow tableRow = new TableRow(this); TextView textView7 = new TextView(this); textView7.setText("" + i); textView7.setTextSize(18); textView7.setTextColor(Color.rgb(0, 0, 0)); textView7.setPadding(15, 0, 15, 0); tableRow.addView(textView7, layoutParams); tableRow.setBackgroundColor(Color.WHITE); final int n = i; tableRow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(personHomeActivity.this, "Click item " + n, Toast.LENGTH_SHORT).show(); } }); mMainLayout.addView(tableRow); TableRow tableRow1 = new TableRow(this); TextView textView1 = new TextView(this); textView1.setText("Test pull down scrollvsfadasdsadsasadsadsadsadsadasdsadasdasdsadsaddasdiew " + i); textView1.setTextSize(16); textView1.setPadding(15, 0, 15, 15); tableRow1.addView(textView1, layoutParams); tableRow1.setBackgroundColor(Color.WHITE); tableRow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(personHomeActivity.this, "Click item " + n, Toast.LENGTH_SHORT).show(); } }); mMainLayout.addView(tableRow1); // TableRow tableRow2 = new TableRow(this); // //tableRow2.addView(textView2, layoutParams); // ImageView imageView = new ImageView(this); // imageView.setImageResource(R.drawable.icon_reply_t); // imageView.setScaleX((float) a); // imageView.setScaleY((float) a); // imageView.setPadding(0, 0, 0, 0); // // ImageView imageView1 = new ImageView(this); // imageView1.setImageResource(R.drawable.icon_thumb_t); // imageView1.setScaleX((float) a); // imageView1.setScaleY((float) a); // imageView1.setPadding(0, 0, 0, 0); // // // //tableRow2.addView(imageView); // tableRow2.addView(imageView1); // mMainLayout.addView(tableRow2); TableLayout mytable = (TableLayout) findViewById(R.id.degital_textTL); int numberOfRow = 1; int numberOfColumn = 12; int cellDimension = 24; int cellPadding = 200; for (int row = 0; row < numberOfRow; row++) { tableRow = new TableRow(this); //tableRow.setLayoutParams(new TableLayout.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT)); tableRow.setLayoutParams(new TableLayout.LayoutParams( (cellDimension + 2 * cellPadding) * numberOfColumn, cellDimension + 2 * cellPadding)); for (int column = 0; column < numberOfColumn; column++) { if (column % 3 == 0) { TextView textView = new TextView(this); textView.setTextSize(20); textView.setText(" "); tableRow.addView(textView); } if (column % 3 == 1) { if (column == 1) { ImageView imageView = new ImageView(this); imageView.setScaleX((float) 0.5); imageView.setScaleY((float) 0.5); imageView.setImageResource(R.drawable.icon_eye_t); tableRow.addView(imageView); } if (column == 4) { ImageView imageView = new ImageView(this); imageView.setScaleX((float) 0.5); imageView.setScaleY((float) 0.5); imageView.setImageResource(R.drawable.icon_thumb_t); tableRow.addView(imageView); } if (column == 7) { ImageView imageView = new ImageView(this); imageView.setScaleX((float) 0.5); imageView.setScaleY((float) 0.5); imageView.setImageResource(R.drawable.icon_reply_t); tableRow.addView(imageView); } if (column == 10) { ImageView imageView = new ImageView(this); imageView.setScaleX((float) 0.5); imageView.setScaleY((float) 0.5); imageView.setImageResource(R.drawable.icon_pencil_t); tableRow.addView(imageView); } } if (column % 3 == 2) { if (column == 2) { TextView textView = new TextView(this); textView.setText("8"); tableRow.addView(textView); } if (column == 5) { TextView textView = new TextView(this); textView.setText("8"); tableRow.addView(textView); } if (column == 8) { TextView textView = new TextView(this); textView.setText("8"); tableRow.addView(textView); } if (column == 11) { TextView textView = new TextView(this); textView.setText("8"); tableRow.addView(textView); } } } mytable.addView(tableRow, new TableLayout.LayoutParams( (cellDimension + 2 * cellPadding) * numberOfColumn, cellDimension + 2 * cellPadding)); //mytable.addView(tableRow,new TableLayout.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT)); } } }
From source file:com.streaming.sweetplayer.MainActivity.java
private void adjustTabs() { if (mTabHost != null) { int tabHeight = 50; int tabsCount = mTabHost.getTabWidget().getTabCount(); for (int i = 0; i < tabsCount; i++) { TextView tabTextView = (TextView) mTabHost.getTabWidget().getChildAt(i) .findViewById(android.R.id.title); tabTextView.setTextSize(9);//w w w . j a va 2s . co m tabTextView.setPadding(2, 0, 2, 0); tabTextView.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); mTabHost.getTabWidget().getChildAt(i) .getLayoutParams().height = (int) (tabHeight * getResources().getDisplayMetrics().density); } } }