List of usage examples for android.widget TextView setTextSize
public void setTextSize(int unit, float size)
From source file:base.PagerSlidingTabStrip.java
private void updateTabStyles() { for (int i = 0; i < tabCount; i++) { View v = tabsContainer.getChildAt(i); // v.setBackgroundResource(tabBackgroundResId); TextView tab_title = (TextView) v.findViewById(R.id.tab_title); if (tab_title != null) { tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab_title.setTypeface(tabTypeface, pager.getCurrentItem() == i ? tabTypefaceSelectedStyle : tabTypefaceStyle); if (tabTextColor != null) { tab_title.setTextColor(tabTextColor); }// w w w .j av a 2s .c o m // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a // pre-ICS-build if (textAllCaps) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { tab_title.setAllCaps(true); } else { tab_title.setText(tab_title.getText().toString().toUpperCase(locale)); } } } } }
From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java
@Override public View getDropDownView(int position, View convertView, ViewGroup parent) { TextView txt = (TextView) convertView; if (txt == null) { txt = new TextView(getApplication()); txt.setPadding(UI._DLGdppad, UI._DLGsppad, UI._DLGdppad, UI._DLGsppad); txt.setTypeface(UI.defaultTypeface); txt.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp); txt.setTextColor(defaultTextColors); }/*from w w w.j a v a 2s .co m*/ txt.setText(getGenreString(position)); return txt; }
From source file:com.earthsea.fish.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)}.//from w w w . j a v a 2s .c om */ protected TextView createDefaultTabView(Context context) { // String activity = context.toString(); // // Log.v("tab_context",activity); // TextView textView = new TextView(context); // // if (activity.contains("SingleReport")) { // textView.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); // } // Instead of messing with layout params maybe we should crank up the padding when we know the // number of tab items will be low but we don't want them to be crammed into the view width 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)); /*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); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(40, padding, 40, padding); return textView; }
From source file:com.ashish.routofy.PagerSlidingTabStrip.java
private void updateTabStyles() { for (int i = 0; i < tabCount; i++) { View v = tabsContainer.getChildAt(i); v.setBackgroundResource(tabBackgroundResId); v.setPadding(tabPadding, v.getPaddingTop(), tabPadding, v.getPaddingBottom()); TextView tab_title = (TextView) v.findViewById(R.id.psts_tab_title); if (tab_title != null) { tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); // setAllCaps() is only available from API 14, so the upper case // is made manually if we are on a // pre-ICS-build if (textAllCaps) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { tab_title.setAllCaps(true); } else { tab_title.setText(tab_title.getText().toString().toUpperCase(locale)); }//from ww w . j ava 2s .co m } } } }
From source file:cn.hollo.www.custom_view.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title);/* w ww.j a va2s. com*/ tab.setGravity(Gravity.CENTER); tab.setSingleLine(); if (tabTextColor != null) tab.setTextColor(tabTextColor); else tab.setTextColor(defaultTabTextColor); tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); addTab(position, tab); }
From source file:com.easemob.easeui.widget.viewpagerindicator.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title);/*from ww w . j a va 2s . c o m*/ tab.setSingleLine(); tab.setTextColor(tabTextColor); tab.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL); tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); addTab(position, tab); }
From source file:com.android.messaging.ui.ViewPagerTabs.java
private void addTab(CharSequence tabTitle, final int position) { final TextView textView = new TextView(getContext()); textView.setText(tabTitle);/*from w ww .j av a 2 s .com*/ textView.setBackgroundResource(R.drawable.contact_picker_tab_background_selector); textView.setGravity(Gravity.CENTER); textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPager.setCurrentItem(getRtlPosition(position)); } }); // Assign various text appearance related attributes to child views. if (mTextStyle > 0) { textView.setTypeface(textView.getTypeface(), mTextStyle); } if (mTextSize > 0) { textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); } if (mTextColor != null) { textView.setTextColor(mTextColor); } textView.setAllCaps(mTextAllCaps); textView.setPadding(mSidePadding, 0, mSidePadding, 0); mTabStrip.addView(textView, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1)); // Default to the first child being selected if (position == 0) { mPrevSelected = 0; textView.setSelected(true); } }
From source file:edu.cens.loci.ui.widget.GenericEditorView.java
private void updateWifiList(TableLayout table, LociWifiFingerprint wifi) { ArrayList<WifiViewListItem> items = new ArrayList<WifiViewListItem>(); HashMap<String, APInfoMapItem> apMap = wifi.getAps(); Set<String> keys = apMap.keySet(); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String bssid = iter.next(); APInfoMapItem ap = apMap.get(bssid); items.add(new WifiViewListItem(bssid, ap.ssid, ap.rss, ap.count, ap.rssBuckets)); }// ww w.j a v a 2 s. c o m Collections.sort(items); table.setColumnCollapsed(0, false); table.setColumnCollapsed(1, true); table.setColumnShrinkable(0, true); for (int i = 0; i < mAddedRows.size(); i++) { table.removeView(mAddedRows.get(i)); } mAddedRows.clear(); int totalCount = wifi.getScanCount(); Context context = getContext(); for (WifiViewListItem item : items) { TableRow row = new TableRow(context); TextView ssidView = new TextView(context); ssidView.setText(item.ssid); //ssidView.setText("very very very veryvery very very very very very"); ssidView.setPadding(2, 2, 2, 2); ssidView.setTextColor(0xffffffff); TextView bssidView = new TextView(context); bssidView.setText(item.bssid); bssidView.setPadding(2, 2, 2, 2); bssidView.setTextColor(0xffffffff); TextView cntView = new TextView(context); cntView.setText("" + (item.count * 100) / totalCount); cntView.setPadding(2, 2, 2, 2); cntView.setGravity(Gravity.CENTER); cntView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); TextView rssView = new TextView(context); rssView.setText("" + item.rss); rssView.setPadding(2, 2, 6, 2); rssView.setGravity(Gravity.CENTER); rssView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); row.addView(ssidView, new TableRow.LayoutParams(0)); row.addView(bssidView, new TableRow.LayoutParams(1)); row.addView(cntView, new TableRow.LayoutParams(2)); row.addView(rssView, new TableRow.LayoutParams(3)); //Log.d(TAG, item.ssid); for (int i = 0; i < item.rssBuckets.length; i++) { TextView box = new TextView(context); box.setText(" "); box.setGravity(Gravity.RIGHT); box.setPadding(2, 2, 2, 2); box.setHeight(15); box.setGravity(Gravity.CENTER_VERTICAL); float colorVal = 256 * ((float) item.rssBuckets[i] / (float) wifi.getScanCount()); //Log.d(TAG, "colorVal=" + (int) colorVal + ", " + item.histogram[i]); int colorValInt = ((int) colorVal) - 1; if (colorValInt < 0) colorValInt = 0; box.setBackgroundColor(0xff000000 + colorValInt);//+ 0x000000ff * (item.histogram[i]/totScan)); box.setTextColor(0xffffffff); row.addView(box, new TableRow.LayoutParams(4 + i)); } row.setGravity(Gravity.CENTER); table.addView(row, new TableLayout.LayoutParams()); table.setColumnStretchable(3, true); mAddedRows.add(row); } }
From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java
private void addRedDotTab(final int position, String title, int resId) { LinearLayout tabLayout = new LinearLayout(getContext()); tabLayout.setOrientation(LinearLayout.HORIZONTAL); tabLayout.setGravity(Gravity.CENTER); TextView tab = new TextView(getContext()); tab.setText(title);/*w ww.j a va 2 s. com*/ tab.setFocusable(true); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); tab.setTextColor(getResources().getColorStateList(R.color.pst_tab_text_selector)); tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f); tabLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (null != mOnPageClickedLisener) { mOnPageClickedLisener.onPageClicked(position); } pager.setCurrentItem(position); } }); tabLayout.addView(tab, 0); ImageView tabImg = new ImageView(getContext()); LinearLayout.LayoutParams tabImgParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tabImgParams.setMargins(DeviceUtils.dip2px(getContext(), 5), DeviceUtils.dip2px(getContext(), 10), 0, 0); tabImgParams.gravity = Gravity.TOP; tabImg.setLayoutParams(tabImgParams); tabLayout.addView(tabImg, 1); tabsContainer.addView(tabLayout); }
From source file:com.example.sam.savemeapp.StatisticsFragment.java
/** * Sets up the initial legend with the contained categories shown * in the pie chart and bullet points with the corresponding colors. *//* ww w. j av a 2s . c om*/ public void setUpPiechart() { pieChart.getDescription().setEnabled(false); Legend pieL = pieChart.getLegend(); Log.d("stats", Float.toString(pieL.getEntries().length)); startLegend = pieL; LegendEntry[] legends = pieL.getEntries(); pieL.setEnabled(false); mLegend.removeAllViews(); //The default legend consist of TextViews and ImageViews which contains a bullet point. //The legends are contained inside of a horizontal LinearLayout which is contained in a vertical LinearLayout. for (int t = 0; t < legends.length - 1; t++) { LegendEntry x = legends[t]; LinearLayout hLayout = new LinearLayout(getContext()); hLayout.setLayoutParams(params); TextView tv = new TextView(getContext()); tv.setText(x.label); tv.setTextColor(x.formColor); tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); LinearLayoutCompat.LayoutParams textViewParams = new LinearLayoutCompat.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textViewParams.setMarginStart((int) getResources().getDimension(R.dimen.statistics_text_margin)); tv.setLayoutParams(textViewParams); ImageView iv = new ImageView(getContext()); Drawable dot = ContextCompat.getDrawable(getContext(), R.drawable.circle_legend); dot.setColorFilter(x.formColor, PorterDuff.Mode.SRC); iv.setImageDrawable(dot); iv.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); hLayout.addView(iv); hLayout.addView(tv); mLegend.addView(hLayout); } designPiechart(); pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { private int color; @Override public void onValueSelected(Entry e, Highlight h) { //it creates new legends with the information of the subcategories when a // category in the pi chart is clicked ArrayList<LegendEntry> list = new ArrayList<>(); mLegend.removeAllViews(); if (e.getData().equals(Color.parseColor("#00a0ae"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Food & Beverage")) { color = x.formColor; } } list.add(new LegendEntry("Food & Beverage: " + u.categories.get("Food & Beverage").get("Food & Beverage") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Restaurant & Caf: " + u.categories.get("Food & Beverage").get("Restaurant & Caf") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Supermarket: " + u.categories.get("Food & Beverage").get("Supermarket") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); //This category legends consist of the main category in this case "Food & Beverage" in the top of the legend //and the sub categories bellow. The name is also shown together with the amount spend in that category. for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#be3127"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Transportation")) { color = x.formColor; } } list.add(new LegendEntry("Transportation: " + u.categories.get("Transportation").get("Transportation") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Public transport: " + u.categories.get("Transportation").get("Public transport") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Taxi & Uber: " + u.categories.get("Transportation").get("Taxi & Uber") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Petrol: " + u.categories.get("Transportation").get("Petrol") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Maintenance: " + u.categories.get("Transportation").get("Maintenance") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#7dc725"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Shopping")) { color = x.formColor; } } list.add(new LegendEntry( "Shopping: " + u.categories.get("Shopping").get("Shopping") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Clothing: " + u.categories.get("Shopping").get("Clothing") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Electronics: " + u.categories.get("Shopping").get("Electronics") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Books: " + u.categories.get("Shopping").get("Books") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Gifts: " + u.categories.get("Shopping").get("Gifts") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Other: " + u.categories.get("Shopping").get("Other") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#e88300"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Entertainment")) { color = x.formColor; } } list.add(new LegendEntry( "Entertainment: " + u.categories.get("Entertainment").get("Entertainment") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Going out: " + u.categories.get("Entertainment").get("Going out") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Sports: " + u.categories.get("Entertainment").get("Sports") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#dc006d"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Health")) { color = x.formColor; } } list.add(new LegendEntry("Health: " + u.categories.get("Health").get("Health") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Doctor: " + u.categories.get("Health").get("Doctor") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Pharmacy: " + u.categories.get("Health").get("Pharmacy") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#1562a4"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Bills")) { color = x.formColor; } } list.add(new LegendEntry("Bills: " + u.categories.get("Bills").get("Bills") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Water: " + u.categories.get("Bills").get("Water") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Electricity: " + u.categories.get("Bills").get("Electricity") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Gas: " + u.categories.get("Bills").get("Gas") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Rent: " + u.categories.get("Bills").get("Rent") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Phone: " + u.categories.get("Bills").get("Phone") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add( new LegendEntry("Insurance: " + u.categories.get("Bills").get("Insurance") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("TV: " + u.categories.get("Bills").get("TV") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Internet: " + u.categories.get("Bills").get("Internet") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } } @Override public void onNothingSelected() { //Sets up the default legend when nothing is selected pieChart = (PieChart) v.findViewById(R.id.piechart); pieChart.setUsePercentValues(true); LegendEntry[] legends = startLegend.getEntries(); startLegend.setEnabled(false); mLegend.removeAllViews(); for (LegendEntry x : legends) { LinearLayout hLayout = new LinearLayout(getContext()); hLayout.setLayoutParams(params); TextView tv = new TextView(getContext()); tv.setText(x.label); tv.setTextColor(x.formColor); tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); LinearLayoutCompat.LayoutParams textViewParams = new LinearLayoutCompat.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textViewParams .setMarginStart((int) getResources().getDimension(R.dimen.statistics_text_margin)); tv.setLayoutParams(textViewParams); ImageView iv = new ImageView(getContext()); Drawable dot = ContextCompat.getDrawable(getContext(), R.drawable.circle_legend); dot.setColorFilter(x.formColor, PorterDuff.Mode.SRC); iv.setImageDrawable(dot); iv.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); hLayout.addView(iv); hLayout.addView(tv); mLegend.addView(hLayout); } } }); }