List of usage examples for android.widget TextView setGravity
public void setGravity(int gravity)
From source file:com.andreapivetta.changemywall.tabs.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)}.//w ww .j av a2 s . com */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); textView.setWidth(size.x / 3); 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)); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); textView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.facebook.notifications.internal.content.TextContent.java
@Override public void applyTo(@NonNull View view) { if (view instanceof TextView) { TextView textView = (TextView) view; textView.setText(getText());// www. j a v a 2 s . c om textView.setTextColor(getTextColor()); Typeface typeface = FontUtilities.parseFont(getTypeface()); typeface = typeface != null ? typeface : Typeface.DEFAULT; textView.setTypeface(typeface); textView.setTextSize(getTypefaceSize()); switch (getTextAlignment()) { case Left: textView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); break; case Center: textView.setGravity(Gravity.CENTER); break; case Right: textView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); break; } } }
From source file:com.contentful.discovery.ui.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { TextView tab = new CFTextView(getContext()); tab.setText(title);// w ww.j a va 2 s . co m tab.setGravity(Gravity.CENTER); tab.setSingleLine(); addTab(position, tab); }
From source file:com.lfq.pulltorefresh.library.sideslip.SwipeMenuLayout.java
@Override protected void onFinishInflate() { super.onFinishInflate(); if (mRightViewId != 0 && mSwipeRightHorizontal == null) { View view = findViewById(mRightViewId); mSwipeRightHorizontal = new SwipeRightHorizontal(view); }/*from www . j a v a 2s .c o m*/ if (mContentViewId != 0 && mContentView == null) { mContentView = findViewById(mContentViewId); } else { TextView errorView = new TextView(getContext()); errorView.setClickable(true); errorView.setGravity(Gravity.CENTER); errorView.setTextSize(16); errorView.setText("You may not have set the ContentView."); mContentView = errorView; addView(mContentView); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppStateObj.java
public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) { JSONObject content = obj.getJson();/*from www . ja va 2 s.co m*/ // TODO: hack to show object history in app feeds JSONObject appState = getAppState(context, content); if (appState != null) { content = appState; } else { Log.e(TAG, "Missing inner content, probably because of format changes"); } boolean rendered = false; AppState ref = new AppState(content); String thumbnail = ref.getThumbnailImage(); if (thumbnail != null) { rendered = true; ImageView imageView = new ImageView(context); imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); App.instance().objectImages.lazyLoadImage(thumbnail.hashCode(), thumbnail, imageView); frame.addView(imageView); } thumbnail = ref.getThumbnailText(); if (thumbnail != null) { rendered = true; TextView valueTV = new TextView(context); valueTV.setText(thumbnail); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.TOP | Gravity.LEFT); frame.addView(valueTV); } thumbnail = ref.getThumbnailHtml(); if (thumbnail != null) { rendered = true; WebView webview = new WebView(context); webview.loadData(thumbnail, "text/html", "UTF-8"); webview.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); Object o = frame.getTag(R.id.object_entry); webview.setOnTouchListener(new WebViewClickListener(frame, (Integer) o)); frame.addView(webview); } if (!rendered) { String appName = content.optString(PACKAGE_NAME); if (appName.contains(".")) { appName = appName.substring(appName.lastIndexOf(".") + 1); } String text = "Welcome to " + appName + "!"; TextView valueTV = new TextView(context); valueTV.setText(text); valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); valueTV.setGravity(Gravity.TOP | Gravity.LEFT); frame.addView(valueTV); } }
From source file:de.madvertise.android.sdk.MadView.java
private void showTextBannerView() { MadUtil.logMessage(null, Log.DEBUG, "Add text banner"); TextView textView = new TextView(getContext()); textView.setGravity(Gravity.CENTER); textView.setText(currentAd.getText()); textView.setTextSize(textSize);// w w w . j a v a 2 s.co m textView.setTextColor(textColor); textView.setTypeface(Typeface.DEFAULT_BOLD); setBackgroundDrawable(textBannerBackground); removeAllViews(); addView(textView); }
From source file:com.astuetz.pagersslidingtabstrip.PagerSlidingTabStrip.java
/** Icon is added here.*/ private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title);/*from w ww . j a v a 2 s . co m*/ tab.setGravity(Gravity.CENTER); tab.setSingleLine(); addTab(position, tab); }
From source file:cn.org.eshow.framwork.view.sliding.AbSlidingSmoothFixTabView.java
/** * ??tab./*from w w w. j ava2s .com*/ * * @param tabTexts the tab texts * @param fragments the fragments */ public void addItemViews(List<String> tabTexts, List<Fragment> fragments) { tabItemTextList.addAll(tabTexts); pagerItemList.addAll(fragments); tabItemList.clear(); mTabLayout.removeAllViews(); for (int i = 0; i < tabItemTextList.size(); i++) { final int index = i; String text = tabItemTextList.get(i); TextView tv = new TextView(this.context); tv.setTextColor(tabColor); tv.setTextSize(tabTextSize); tv.setText(text); tv.setGravity(Gravity.CENTER); tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1)); tv.setPadding(12, 5, 12, 5); tv.setFocusable(false); tabItemList.add(tv); mTabLayout.addView(tv); tv.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mViewPager.setCurrentItem(index); } }); } //? mFragmentPagerAdapter.notifyDataSetChanged(); mViewPager.setCurrentItem(0); computeTabImg(0); }
From source file:cn.org.eshow.framwork.view.sliding.AbSlidingSmoothFixTabView.java
/** * ??tab./* w w w . java 2 s.com*/ * * @param tabText the tab text * @param fragment the fragment */ public void addItemView(String tabText, Fragment fragment) { tabItemTextList.add(tabText); pagerItemList.add(fragment); tabItemList.clear(); mTabLayout.removeAllViews(); for (int i = 0; i < tabItemTextList.size(); i++) { final int index = i; String text = tabItemTextList.get(i); TextView tv = new TextView(this.context); tv.setTextColor(tabColor); tv.setTextSize(tabTextSize); tv.setText(text); tv.setGravity(Gravity.CENTER); tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1)); tv.setPadding(12, 5, 12, 5); tv.setFocusable(false); tabItemList.add(tv); mTabLayout.addView(tv); tv.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mViewPager.setCurrentItem(index); } }); } //? AbLogUtil.d(AbSlidingSmoothFixTabView.class, "addItemView finish"); mFragmentPagerAdapter.notifyDataSetChanged(); mViewPager.setCurrentItem(0); computeTabImg(0); }
From source file:com.bangqu.eshow.view.sliding.ESSlidingSmoothFixTabView.java
/** * ??tab./*from w w w. ja v a 2 s . c o m*/ * * @param tabText the tab text * @param fragment the fragment */ public void addItemView(String tabText, Fragment fragment) { tabItemTextList.add(tabText); pagerItemList.add(fragment); tabItemList.clear(); mTabLayout.removeAllViews(); for (int i = 0; i < tabItemTextList.size(); i++) { final int index = i; String text = tabItemTextList.get(i); TextView tv = new TextView(this.context); tv.setTextColor(tabColor); tv.setTextSize(tabTextSize); tv.setText(text); tv.setGravity(Gravity.CENTER); tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1)); tv.setPadding(12, 5, 12, 5); tv.setFocusable(false); tabItemList.add(tv); mTabLayout.addView(tv); tv.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mViewPager.setCurrentItem(index); } }); } //? ESLogUtil.d(ESSlidingSmoothFixTabView.class, "addItemView finish"); mFragmentPagerAdapter.notifyDataSetChanged(); mViewPager.setCurrentItem(0); computeTabImg(0); }