List of usage examples for android.widget TextView setGravity
public void setGravity(int gravity)
From source file:at.wada811.app.fragment.ExpandableListFragment.java
/** * Provide default implementation to return a expandable list view. Subclasses * can override to replace with their own layout. If doing so, the returned * view hierarchy <em>must</em> have a ExpandableListView whose id * is {@link android.R.id#list android.R.id.list} and can optionally * have a sibling view id {@link android.R.id#empty android.R.id.empty} that is to be shown when * the list is empty.//from ww w . j av a 2 s . c om * * <p> * If you are overriding this method with your own custom content, consider including the * standard layout {@link android.R.layout#list_content} in your layout file, so that you * continue to retain all of the standard behavior of ExpandableListFragment. In particular, * this is currently the only way to have the built-in indeterminant progress state be shown. * * @param inflater The LayoutInflater object that can be used to inflate any views in the * fragment, * @param container If non-null, this is the parent view that the fragment's UI should be * attached to. The fragment should not add the view itself, but this can be used to * generate the LayoutParams of the view. * @param savedInstanceState If non-null, this fragment is being re-constructed from a previous * saved state as given here. * @return Return the View for the fragment's UI, or null. */ @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final Context context = getActivity(); final FrameLayout root = new FrameLayout(context); // ------------------------------------------------------------------ final LinearLayout pframe = new LinearLayout(context); pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID); pframe.setOrientation(LinearLayout.VERTICAL); pframe.setVisibility(View.GONE); pframe.setGravity(Gravity.CENTER); final ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge); pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // ------------------------------------------------------------------ final FrameLayout lframe = new FrameLayout(context); lframe.setId(INTERNAL_LIST_CONTAINER_ID); final TextView tv = new TextView(getActivity()); tv.setId(INTERNAL_EMPTY_ID); tv.setGravity(Gravity.CENTER); lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); final ExpandableListView lv = new ExpandableListView(getActivity()); lv.setId(android.R.id.list); lv.setDrawSelectorOnTop(false); lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // ------------------------------------------------------------------ root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return root; }
From source file:com.example.testing.myapplication.module.pageSliding.PagerSlidingTabStrip.java
private void addTextTab(final int position, final String title) { TextView tab = new TextView(getContext()); tab.setText(title);//from w w w .jav a 2 s. c o m tab.setGravity(Gravity.CENTER); tab.setSingleLine(); tab.setFocusable(true); //tab.setOnClickListener(new OnClickListener() { // @Override public void onClick(View v) { // pager.setCurrentItem(position); // v.setSelected(true); // } //}); tab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pager.setCurrentItem(position); v.setSelected(true); } }); tab.setPadding(tabPadding, 0, tabPadding, 0); tab.setBackgroundResource(tabBackgroundResId); tab.setTextColor(mTabTextColor); tab.setTextSize(tabTextSize); //tab.setTypeface(tabTypeface, tabTypefaceStyle); tab.setSelected(position == 0); // 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.setAllCaps(true); } else { tab.setText(tab.getText().toString().toUpperCase(locale)); } } tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); }
From source file:angeloid.dreamnarae.SwipeyTabs.java
/** * Update the ellipsize of the text views *///from w w w .j a v a 2 s . c o m private void updateEllipsize() { if (mAdapter == null) { return; } final int count = mAdapter.getCount(); for (int i = 0; i < count; i++) { TextView tab = (TextView) getChildAt(i); if (i < mCurrentPos) { tab.setEllipsize(null); tab.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); } else if (i == mCurrentPos) { tab.setEllipsize(TruncateAt.END); tab.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); } else if (i > mCurrentPos) { tab.setEllipsize(null); tab.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); } } }
From source file:com.hobby.uiframework.widget.PagerSlidingTab.java
private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title);/* w w w.j a v a 2 s .c o m*/ tab.setGravity(Gravity.CENTER); tab.setSingleLine(); tab.setTag(title + position); addTab(position, tab); }
From source file:com.axolotl.yanews.customize.SlidingTabLayout.java
/** * tabview. tab view//ww w . j a v a 2s .com * {@link #setCustomTabView(int, int)}. */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context, null, 0); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTab_text_size_sp); if (mBold) { textView.setTypeface(Typeface.DEFAULT, Typeface.BOLD); } else { textView.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); } if (mChangeTextColor) { textView.setTextColor(mNormalColor); } textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); if (mBackgroundResource != 0) { textView.setBackgroundResource(mBackgroundResource); } else { 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); } } //wtf // 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(padding, 0, padding, 0); return textView; }
From source file:com.jinzht.pro.smarttablayout.SmartTabLayout.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 a v a 2 s . c o m*/ */ protected TextView createDefaultTabView(CharSequence title) { TextView textView = new TextView(getContext()); textView.setGravity(Gravity.CENTER); textView.setText(title); textView.setTextColor(tabViewTextColors); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setSingleLine(true); UiHelp.textBold(textView); textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); if (tabViewBackgroundResId != NO_ID) { textView.setBackgroundResource(tabViewBackgroundResId); } else 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(tabViewTextAllCaps); } textView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0); if (tabViewTextMinWidth > 0) { textView.setMinWidth(tabViewTextMinWidth); } return textView; }
From source file:com.chess.genesis.view.SwipeTabs.java
/** * Update the ellipsize of the text views *///from w w w.j av a2 s .c o m private void updateEllipsize() { if (mAdapter == null) return; final int count = mAdapter.getCount(); for (int i = 0; i < count; i++) { final TextView tab = (TextView) getChildAt(i); if (i < mCurrentPos) { tab.setEllipsize(null); tab.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); } else if (i == mCurrentPos) { tab.setEllipsize(TruncateAt.END); tab.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL); } else if (i > mCurrentPos) { tab.setEllipsize(null); tab.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL); } } }
From source file:com.do_an_httt.truon_000.jobssocialnetwork.view.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 . java 2 s . c om*/ */ protected TextView createDefaultTabView(Context context) { int width_device = getResources().getDisplayMetrics().widthPixels; TextView textView = new TextView(context); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(width_device / 3, ViewGroup.LayoutParams.MATCH_PARENT); textView.setLayoutParams(params); 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); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.ehelp.home.SuperAwesomeCardFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); FrameLayout fl = new FrameLayout(getActivity()); fl.setLayoutParams(params);/*from www .ja v a 2 s. c o m*/ //fl.setBackgroundColor(0x666666); final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()); TextView v = new TextView(getActivity()); params.setMargins(margin, margin, margin, margin); v.setLayoutParams(params); v.setGravity(Gravity.TOP); System.out.println(position); if (position == 0) { fl.removeAllViews(); mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL; mMapView = new MapView(getActivity()); mMapView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); fl.addView(mMapView); mBaiduMap = mMapView.getMap(); // ?? mBaiduMap.setMyLocationEnabled(true); // ?? mLocClient = new LocationClient(getActivity()); mLocClient.registerLocationListener(myListener); LocationClientOption option = new LocationClientOption(); option.setOpenGps(true);// gps option.setCoorType("bd09ll"); // ?? option.setScanSpan(1000); mLocClient.setLocOption(option); mLocClient.start(); int count = mMapView.getChildCount(); for (int i = 0; i < count; i++) { View child = mMapView.getChildAt(i); if (child instanceof ZoomControls || child instanceof ImageView) { child.setVisibility(View.INVISIBLE); } } setLocation(); } else if (position == 1) { fl.removeAllViews(); ListView queList = new ListView(getActivity()); queList.setLayoutParams(new LinearLayout.LayoutParams(-1, -1)); HomeAdapter que = new HomeAdapter(getActivity(), user_id, 2, eventCache); queList.setAdapter(que); queList.setDividerHeight(20); fl.addView(queList); events = que.getEvent(); //? queList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) { Intent intent = new Intent(getActivity(), recievesos_map.class); int eventid = events.get(index).getEventId(); intent.putExtra(EXTRA_MESSAGE, eventid); startActivity(intent); } }); } else if (position == 2) { fl.removeAllViews(); ListView queList = new ListView(getActivity()); queList.setLayoutParams(new LinearLayout.LayoutParams(-1, -1)); //queList.setBackgroundColor(0x666666); //queList.setAlpha(125); queList.setDividerHeight(20); HomeAdapter que = new HomeAdapter(getActivity(), user_id, 1, eventCache); queList.setAdapter(que); fl.addView(queList); events = que.getEvent(); //? queList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) { Intent intent = new Intent(getActivity(), recieve_help_ans_map.class); intent.putExtra(EXTRA_MESSAGE, events.get(index)); startActivity(intent); } }); } else if (position == 3) { fl.removeAllViews(); ListView queList = new ListView(getActivity()); queList.setLayoutParams(new LinearLayout.LayoutParams(-1, -1)); HomeAdapter que = new HomeAdapter(getActivity(), user_id, 0, eventCache); queList.setAdapter(que); queList.setDividerHeight(20); fl.addView(queList); events = que.getEvent(); //? queList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) { Intent intent = new Intent(getActivity(), QuestionDetail.class); intent.putExtra("qusetiondatail", events.get(index)); startActivity(intent); } }); } return fl; }
From source file:com.materialdesign.view.tab.TabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * ./*from w w w. j av a 2 s . co m*/ */ protected View createDefaultTabView(Context context) { View tabView = LayoutInflater.from(context).inflate(R.layout.tab_layout, null); TextView textView = (TextView) tabView.findViewById(R.id.tv_tabText); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTabViewTextDefaultSize); textView.setTypeface(Typeface.DEFAULT); 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) (mTabViewDefaultPadding * getResources().getDisplayMetrics().density); textView.setPadding(0, padding, 0, padding); return tabView; }