本文整理匯總了Java中android.widget.TextView.setGravity方法的典型用法代碼示例。如果您正苦於以下問題:Java TextView.setGravity方法的具體用法?Java TextView.setGravity怎麽用?Java TextView.setGravity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.TextView
的用法示例。
在下文中一共展示了TextView.setGravity方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addTextView
import android.widget.TextView; //導入方法依賴的package包/類
private void addTextView(Context context, int viewTag) {
TextView tv = (TextView) View.inflate(context, R.layout.custom_textview, null);
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
layoutParams.weight = 1.0F;
tv.setLayoutParams(layoutParams);
tv.setOnClickListener(this);
tv.setGravity(Gravity.CENTER);
if (mTextSize > 0f)
tv.setTextSize(0, mTextSize);
tv.setOnClickListener(this);
tv.setTag(viewTag);
if (viewTag == TAG_LEFT_VIEW) {
tv.setText(mLeftText);
mLeftTextView = tv;
} else if (viewTag == TAG_NONE_VIEW) {
tv.setText(mSimpleText);
mSimpleTextView = tv;
} else if (viewTag == TAG_RIGHT_VIEW) {
tv.setText(mRightText);
mRightTextView = tv;
}
addView(tv);
}
示例2: showDialog
import android.widget.TextView; //導入方法依賴的package包/類
private void showDialog() {
Builder builder = new Builder(this.mContext);
TextView title = new TextView(this.mContext);
title.setText("分享失敗原因");
title.setPadding(0, 20, 0, 20);
title.setTextColor(-1);
title.setGravity(17);
title.setTextSize(16.0f);
builder.setCustomTitle(title);
TextView textView = new TextView(this.mContext);
textView.setText("請添加QQ平台到SDK \n添加方式:\nUMQQSsoHandler qqSsoHandler = new UMQQSsoHandler" +
"(getActivity(), \"你的APP ID\",\"你的APP KEY\");\nqqSsoHandler.addToSocialSDK(); " +
"\n參考文檔:\nhttp://dev.umeng" +
".com/social/android/share/quick-integration#social_qq_sso");
textView.setTextColor(-1);
textView.setTextSize(16.0f);
textView.setAutoLinkMask(1);
builder.setView(textView);
builder.show().show();
}
示例3: onCreate
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (PasswordUIView.shouldUseSmartLockBranding()) {
getActivity().setTitle(R.string.prefs_smart_lock_for_passwords);
} else {
getActivity().setTitle(R.string.prefs_saved_passwords);
}
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(getActivity()));
mPasswordManagerHandler.addObserver(this);
mEmptyView = new TextView(getActivity(), null);
mEmptyView.setText(R.string.saved_passwords_none_text);
mEmptyView.setGravity(Gravity.CENTER);
mEmptyView.setVisibility(View.GONE);
}
示例4: addItemView
import android.widget.TextView; //導入方法依賴的package包/類
private View addItemView(int rid, String text) {
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setId(rid);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, DensityUtil.dip2px(context, 44f)));
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setBackgroundResource(R.drawable.base_item_bg_selector);
linearLayout.setOnClickListener(this);
TextView textView = new TextView(context);
textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
textView.setText(text);
textView.setTextColor(context.getResources().getColor(R.color.bottom_dialog_textcolor));
textView.setTextSize(16f);
textView.setGravity(Gravity.CENTER);
linearLayout.removeAllViews();
linearLayout.addView(textView);
return linearLayout;
}
示例5: EmptyTextProgressView
import android.widget.TextView; //導入方法依賴的package包/類
public EmptyTextProgressView(Context context) {
super(context);
progressBar = new ProgressBar(context);
progressBar.setVisibility(INVISIBLE);
addView(progressBar, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
textView = new TextView(context);
textView.setTypeface(FontManager.instance().getTypeface());
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
textView.setTextColor(0xff808080);
textView.setGravity(Gravity.CENTER);
textView.setVisibility(INVISIBLE);
textView.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
textView.setText(LocaleController.getString("NoResult", R.string.NoResult));
addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
}
示例6: SearchButton
import android.widget.TextView; //導入方法依賴的package包/類
public SearchButton(Context context) {
super(context);
setBackgroundColor(0xff1a1a1a);
selector = new View(context);
selector.setBackgroundResource(R.drawable.list_selector);
addView(selector, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER);
addView(imageView, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
textView1 = new TextView(context);
textView1.setTypeface(FontManager.instance().getTypeface());
textView1.setGravity(Gravity.CENTER_VERTICAL);
textView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView1.setTypeface(FontManager.instance().getTypeface());
textView1.setTextColor(0xffffffff);
textView1.setSingleLine(true);
textView1.setEllipsize(TextUtils.TruncateAt.END);
addView(textView1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 51, 8, 4, 0));
textView2 = new TextView(context);
textView2.setTypeface(FontManager.instance().getTypeface());
textView2.setGravity(Gravity.CENTER_VERTICAL);
textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
textView2.setTypeface(FontManager.instance().getTypeface());
textView2.setTextColor(0xff666666);
textView2.setSingleLine(true);
textView2.setEllipsize(TextUtils.TruncateAt.END);
addView(textView2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 51, 26, 4, 0));
}
示例7: onCreateDialogView
import android.widget.TextView; //導入方法依賴的package包/類
@Override
protected View onCreateDialogView() {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
// Layout returned as dialog view
LinearLayout layout = new LinearLayout(mContext);
layout.setOrientation(LinearLayout.VERTICAL);
// Add text view to show the current value
mViewValue = new TextView(mContext);
mViewValue.setGravity(Gravity.CENTER_HORIZONTAL);
mViewValue.setText(String.valueOf(mValue));
layout.addView(mViewValue, params);
// Add seek bar
mSeekBar = new SeekBar(mContext);
mSeekBar.setMax(mMax);
mSeekBar.setProgress(mValue);
// Set progress before change listener
mSeekBar.setOnSeekBarChangeListener(this);
layout.addView(mSeekBar, params);
return layout;
}
示例8: init
import android.widget.TextView; //導入方法依賴的package包/類
private void init(Context context) {
if (isInEditMode()) return;
mIndicatorView = new AVLoadingIndicatorView(context);
mIndicatorView.setIndicatorId(AVLoadingIndicatorView.Pacman);
mIndicatorView.setIndicatorColor(Color.WHITE);
mIndicatorView.setId(R.id.left);
RelativeLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(CENTER_IN_PARENT);
addView(mIndicatorView, layoutParams);
mText = new TextView(context);
mText.setEms(6);
mText.setGravity(Gravity.CENTER);
RelativeLayout.LayoutParams textLayoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
textLayoutParams.addRule(CENTER_IN_PARENT);
textLayoutParams.addRule(BELOW, mIndicatorView.getId());
addView(mText, textLayoutParams);
}
示例9: FrameLayout
import android.widget.TextView; //導入方法依賴的package包/類
private void addIconTabBådeTekstOgBillede(final int position, int resId, String url, String title) {
FrameLayout tabfl = new FrameLayout(getContext());
ImageView tabi = new ImageView(getContext());
tabi.setContentDescription(title);
//Log.d(title+" "+resId + " Kanallogo URL="+url);
if (resId==0) {
Picasso.with(tabi.getContext())
.load(url).placeholder(null)
.into(tabi);
tabi.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
tabi.setAdjustViewBounds(true);
tabi.setVisibility(View.GONE);
} else {
tabi.setImageResource(resId);
tabi.setVisibility(View.INVISIBLE);
}
TextView tabt = new TextView(getContext());
tabt.setText(title);
tabt.setTypeface(App.skrift_gibson);
tabt.setGravity(Gravity.CENTER);
tabt.setSingleLine();
tabfl.addView(tabi);
tabfl.addView(tabt);
LayoutParams lp = (LayoutParams) tabi.getLayoutParams();
lp.gravity=Gravity.CENTER;
lp.width=lp.height=ViewGroup.LayoutParams.MATCH_PARENT;
lp = (LayoutParams) tabt.getLayoutParams();
lp.width=lp.height=ViewGroup.LayoutParams.MATCH_PARENT;
lp.gravity=Gravity.CENTER;
addTab(position, tabfl);
}
示例10: getItemTextView
import android.widget.TextView; //導入方法依賴的package包/類
public static TextView getItemTextView(Context context, MenuObject menuItem, int menuItemSize,
View.OnClickListener onCLick, View.OnLongClickListener onLongClick) {
TextView itemTextView = new TextView(context);
RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, menuItemSize);
itemTextView.setLayoutParams(textLayoutParams);
itemTextView.setOnClickListener(onCLick);
itemTextView.setOnLongClickListener(onLongClick);
itemTextView.setText(menuItem.getTitle());
itemTextView.setPadding(0, 0, (int) context.getResources().getDimension(R.dimen.text_right_padding), 0);
itemTextView.setGravity(Gravity.CENTER_VERTICAL);
int textColor = menuItem.getTextColor() == 0 ?
android.R.color.white :
menuItem.getTextColor();
itemTextView.setTextColor(ContextCompat.getColor(context, textColor));
int styleResId = menuItem.getMenuTextAppearanceStyle() > 0
? menuItem.getMenuTextAppearanceStyle()
: R.style.TextView_DefaultStyle;
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
itemTextView.setTextAppearance(context, styleResId);
} else {
itemTextView.setTextAppearance(styleResId);
}
return itemTextView;
}
示例11: getLoadingView
import android.widget.TextView; //導入方法依賴的package包/類
private View getLoadingView() {
TextView tv = new TextView(this);
tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
tv.setText("Helper中定義的加載中");
tv.setGravity(Gravity.CENTER);
tv.setTextSize(18);
tv.setTextColor(Color.RED);
// 設置tag為loading
tv.setTag(StatusLayout.Status.LOADING.getStatus());
return tv;
}
示例12: setSpinnerText
import android.widget.TextView; //導入方法依賴的package包/類
private void setSpinnerText(View view) {
view.setBackgroundColor(getResources().getColor(R.color.in));
TextView textView = (TextView) view;
textView.setTextColor(getResources().getColor(R.color.ax));
textView.setTextSize(16.0f);
textView.setGravity(19);
}
示例13: init
import android.widget.TextView; //導入方法依賴的package包/類
/**
*
*/
private void init() {
int dip2px = DensityUtil.dip2px(2.0F);
padding = getResources().getDimensionPixelSize(R.dimen.SmallestPadding);
TextView description = new TextView(getContext());
description.setSingleLine();
description.setEllipsize(TextUtils.TruncateAt.END);
description.setTextColor(getResources().getColor(R.color.ccp_green));
description.setTextSize(TypedValue.COMPLEX_UNIT_PX , getResources().getDimensionPixelSize(R.dimen.HintTextSize) + dip2px);
description.setText(R.string.tab_view_name);
description.setTypeface(null, Typeface.NORMAL);
addView(mTabDescription = description);
ImageView descriptionImage = new ImageView(getContext());
descriptionImage.setImageResource(R.drawable.unread_dot);
descriptionImage.setVisibility(View.INVISIBLE);
addView(mTabImage = descriptionImage);
TextView tips = new TextView(getContext());
tips.setTextColor(getResources().getColor(android.R.color.white));
tips.setTextSize(0, getResources().getDimensionPixelSize(R.dimen.SmallestTextSize));
tips.setBackgroundResource(R.drawable.to_read_tips_onbackbtn);
tips.setGravity(Gravity.CENTER);
tips.setVisibility(View.INVISIBLE);
addView(mTabUnreadTips = tips);
setBackgroundResource(R.drawable.tab_item_bg);
}
示例14: configureTextView
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Configures text view. Is called for the TEXT_VIEW_ITEM_RESOURCE views.
* @param view the text view to be configured
*/
protected void configureTextView(TextView view) {
view.setTextColor(textColor);
view.setGravity(Gravity.CENTER);
view.setTextSize(textSize);
view.setEllipsize(TextUtils.TruncateAt.END);
view.setLines(1);
// view.setCompoundDrawablePadding(20);
// view.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
}
示例15: addTextTab
import android.widget.TextView; //導入方法依賴的package包/類
private void addTextTab(final int position, String title) {
View layoutView = View.inflate(getContext(), R.layout.layout_tv, null);
TextView tab = (TextView) layoutView.findViewById(R.id.tv_content);
tab.setText(title);
tab.setGravity(Gravity.CENTER);
tab.setSingleLine();
addTab(position, tab, layoutView);
}