Java Code Examples for android.widget.TextView.setIncludeFontPadding()

The following are Jave code examples for showing how to use setIncludeFontPadding() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ListItemView   File: ListItemView.java   View Source Code Vote up 6 votes
private void setupTextView(final TextView textView, final int leading, final int step) {
    // This is to make the behavior more deterministic: remove extra top/bottom padding
    textView.setIncludeFontPadding(false);

    // Get font metrics and calculate required inter-line extra
    Paint.FontMetricsInt metrics = textView.getPaint().getFontMetricsInt();
    final int extra = leading - metrics.descent + metrics.ascent;
    textView.setLineSpacing(extra, 1);

    // Determine minimum required top extra so that the view lands on the grid
    final int alignTopExtra = (step + metrics.ascent % step) % step;
    // Determine minimum required bottom extra so that view bounds are aligned with the grid
    final int alignBottomExtra = (step - metrics.descent % step) % step;

    textView.setPadding(textView.getPaddingLeft(), textView.getPaddingTop() + alignTopExtra,
            textView.getPaddingRight(), textView.getPaddingBottom() + alignBottomExtra);
}
 
Example 2
Project: Hitalk   File: WheelItem.java   View Source Code Vote up 6 votes
/**
 * 初始化
 */
private void init() {
    LinearLayout layout = new LinearLayout(getContext());
    LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, WheelUtils.dip2px(getContext(),
            WheelConstants
                    .WHEEL_ITEM_HEIGHT));
    layout.setOrientation(LinearLayout.HORIZONTAL);
    layout.setPadding(WheelConstants.WHEEL_ITEM_PADDING, WheelConstants.WHEEL_ITEM_PADDING, WheelConstants
            .WHEEL_ITEM_PADDING, WheelConstants.WHEEL_ITEM_PADDING);
    layout.setGravity(Gravity.CENTER);
    addView(layout, layoutParams);

    // 图片
    mImage = new ImageView(getContext());
    mImage.setTag(WheelConstants.WHEEL_ITEM_IMAGE_TAG);
    mImage.setVisibility(View.GONE);
    LayoutParams imageParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    imageParams.rightMargin = WheelConstants.WHEEL_ITEM_MARGIN;
    layout.addView(mImage, imageParams);

    // 文本
    mText = new TextView(getContext());
    mText.setTag(WheelConstants.WHEEL_ITEM_TEXT_TAG);
    mText.setEllipsize(TextUtils.TruncateAt.END);
    mText.setSingleLine();
    mText.setIncludeFontPadding(false);
    mText.setGravity(Gravity.CENTER);
    mText.setTextColor(Color.BLACK);
    LayoutParams textParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    layout.addView(mText, textParams);
}
 
Example 3
Project: android-project-gallery   File: XPreference.java   View Source Code Vote up 6 votes
public void addHintIcon(int drawableId)
{
	if (this.mHintIconArray.indexOfKey(drawableId) == -1)
	{
		this.mHintIconArray.put(drawableId, drawableId);
		
		TextView tv = new TextView(mContext);
		tv.setTag(drawableId);
		tv.setGravity(Gravity.CENTER);
		ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
		tv.setLayoutParams(lp);
		tv.setBackgroundResource(drawableId);
		tv.setIncludeFontPadding(false);
		
		this.mHintIcons.addView(tv);
	}
}
 
Example 4
Project: android-project-gallery   File: XPreferenceGreen.java   View Source Code Vote up 6 votes
public void addHintIcon(int drawableId)
{
	if (this.mHintIconArray.indexOfKey(drawableId) == -1)
	{
		this.mHintIconArray.put(drawableId, drawableId);
		
		TextView tv = new TextView(mContext);
		tv.setTag(drawableId);
		tv.setGravity(Gravity.CENTER);
		ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
		tv.setLayoutParams(lp);
		tv.setBackgroundResource(drawableId);
		tv.setIncludeFontPadding(false);
		
		this.mHintIcons.addView(tv);
	}
}
 
Example 5
Project: GitHub   File: WheelListView.java   View Source Code Vote up 5 votes
private void init(Context context) {
    setOrientation(LinearLayout.HORIZONTAL);
    int paddingTopBottom = ConvertUtils.toPx(context, ITEM_PADDING_TOP_BOTTOM);
    int paddingLeftRight = ConvertUtils.toPx(context, ITEM_PADDING_LEFT_RIGHT);
    setPadding(paddingLeftRight, paddingTopBottom, paddingLeftRight, paddingTopBottom);
    setGravity(Gravity.CENTER);
    int height = ConvertUtils.toPx(context, ITEM_HEIGHT);
    // fixed: 17-1-8 #79 安卓4.x兼容问题,java.lang.ClassCastException……onMeasure……
    setLayoutParams(new AbsListView.LayoutParams(MATCH_PARENT, height));

    imageView = new ImageView(getContext());
    imageView.setTag(ITEM_TAG_IMAGE);
    imageView.setVisibility(View.GONE);
    LayoutParams imageParams = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    imageParams.rightMargin = ConvertUtils.toPx(context, ITEM_MARGIN);
    addView(imageView, imageParams);

    textView = new TextView(getContext());
    textView.setTag(ITEM_TAG_TEXT);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setSingleLine(true);
    textView.setIncludeFontPadding(false);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(Color.BLACK);
    LayoutParams textParams = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    addView(textView, textParams);
}
 
Example 6
Project: MyFire   File: GoodView.java   View Source Code Vote up 5 votes
private void initView() {
    RelativeLayout layout = new RelativeLayout(mContext);
    RelativeLayout.LayoutParams params =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

    mGood = new TextView(mContext);
    mGood.setIncludeFontPadding(false);
    mGood.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mTextSize);
    mGood.setTextColor(ContextCompat.getColor(mContext, mTextColor));
    mGood.setText(mText);
    mGood.setLayoutParams(params);
    layout.addView(mGood);
    setContentView(layout);

    int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    mGood.measure(w, h);
    setWidth(mGood.getMeasuredWidth());
    setHeight(mDistance + mGood.getMeasuredHeight());
    setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    setFocusable(false);
    setTouchable(false);
    setOutsideTouchable(false);

    mAnimationSet = createAnimation();
}
 
Example 7
Project: ywApplication   File: PlatformGridView.java   View Source Code Vote up 5 votes
private LinearLayout getView(int position, OnClickListener ocL, Context context) {
	Bitmap logo;
	String label;
	OnClickListener listener;
	if (beans[position] instanceof Platform) {
		logo = getIcon((Platform) beans[position]);
		label = getName((Platform) beans[position]);
		listener = ocL;
	} else {
		logo = ((CustomerLogo) beans[position]).enableLogo;
		label = ((CustomerLogo) beans[position]).label;
		listener = ocL;
	}

	LinearLayout ll = new LinearLayout(context);
	ll.setOrientation(LinearLayout.VERTICAL);

	ImageView iv = new ImageView(context);
	int dp_5 = com.mob.tools.utils.R.dipToPx(context, 5);
	iv.setPadding(dp_5, dp_5, dp_5, dp_5);
	iv.setScaleType(ScaleType.CENTER_INSIDE);
	LayoutParams lpIv = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpIv.setMargins(dp_5, dp_5, dp_5, dp_5);
	lpIv.gravity = Gravity.CENTER_HORIZONTAL;
	iv.setLayoutParams(lpIv);
	iv.setImageBitmap(logo);
	ll.addView(iv);

	TextView tv = new TextView(context);
	tv.setTextColor(0xff000000);
	tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
	tv.setSingleLine();
	tv.setIncludeFontPadding(false);
	LayoutParams lpTv = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpTv.gravity = Gravity.CENTER_HORIZONTAL;
	lpTv.weight = 1;
	lpTv.setMargins(dp_5, 0, dp_5, dp_5);
	tv.setLayoutParams(lpTv);
	tv.setText(label);
	ll.addView(tv);
	ll.setOnClickListener(listener);

	return ll;
}
 
Example 8
Project: Renrentou   File: GoodView.java   View Source Code Vote up 5 votes
private void initView() {
    RelativeLayout layout = new RelativeLayout(mContext);
    RelativeLayout.LayoutParams params =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

    mGood = new TextView(mContext);
    mGood.setIncludeFontPadding(false);
    mGood.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mTextSize);
    mGood.setTextColor(mTextColor);
    mGood.setText(mText);
    mGood.setLayoutParams(params);
    layout.addView(mGood);
    setContentView(layout);

    int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    mGood.measure(w, h);
    setWidth(mGood.getMeasuredWidth());
    setHeight(mDistance + mGood.getMeasuredHeight());
    setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    setFocusable(false);
    setTouchable(false);
    setOutsideTouchable(false);

    mAnimationSet = createAnimation();
}
 
Example 9
Project: Hotspot-master-devp   File: PagerSlidingTabStrip.java   View Source Code Vote up 5 votes
private void addTextTab(final int position, String title) {
    TextView tab = new TextView(getContext());
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setIncludeFontPadding(false);

    TextView tab2 = new TextView(getContext());
    tab2.setText(title);
    tab2.setGravity(Gravity.CENTER);
    tab2.setSingleLine();
    tab2.setIncludeFontPadding(false);

    addTab(position, tab, tab2);
}
 
Example 10
Project: boohee_v5.6   File: PlatformGridView.java   View Source Code Vote up 5 votes
private LinearLayout getView(int position, OnClickListener ocL, Context context) {
    Bitmap logo;
    String label;
    OnClickListener listener;
    if (this.beans[position] instanceof Platform) {
        logo = getIcon((Platform) this.beans[position]);
        label = getName((Platform) this.beans[position]);
        listener = ocL;
    } else {
        logo = ((CustomerLogo) this.beans[position]).enableLogo;
        label = ((CustomerLogo) this.beans[position]).label;
        listener = ocL;
    }
    LinearLayout ll = new LinearLayout(context);
    ll.setOrientation(1);
    ImageView iv = new ImageView(context);
    int dp_5 = R.dipToPx(context, 5);
    iv.setPadding(dp_5, dp_5, dp_5, dp_5);
    iv.setScaleType(ScaleType.CENTER_INSIDE);
    LayoutParams lpIv = new LayoutParams(-2, -2);
    lpIv.setMargins(dp_5, dp_5, dp_5, dp_5);
    lpIv.gravity = 1;
    iv.setLayoutParams(lpIv);
    iv.setImageBitmap(logo);
    ll.addView(iv);
    TextView tv = new TextView(context);
    tv.setTextColor(AbstractWheelTextAdapter.DEFAULT_TEXT_COLOR);
    tv.setTextSize(1, 14.0f);
    tv.setSingleLine();
    tv.setIncludeFontPadding(false);
    LayoutParams lpTv = new LayoutParams(-2, -2);
    lpTv.gravity = 1;
    lpTv.weight = 1.0f;
    lpTv.setMargins(dp_5, 0, dp_5, dp_5);
    tv.setLayoutParams(lpTv);
    tv.setText(label);
    ll.addView(tv);
    ll.setOnClickListener(listener);
    return ll;
}
 
Example 11
Project: RLibrary   File: GoodView.java   View Source Code Vote up 5 votes
private void initView() {
    RelativeLayout layout = new RelativeLayout(mContext);
    RelativeLayout.LayoutParams params =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

    mGood = new TextView(mContext);
    mGood.setIncludeFontPadding(false);
    mGood.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mTextSize);
    mGood.setTextColor(mTextColor);
    mGood.setText(mText);
    mGood.setLayoutParams(params);
    layout.addView(mGood);
    setContentView(layout);

    int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    mGood.measure(w, h);
    setWidth(mGood.getMeasuredWidth());
    setHeight(mDistance + mGood.getMeasuredHeight());
    setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    setFocusable(false);
    setTouchable(false);
    setOutsideTouchable(false);

    mAnimationSet = createAnimation();
}
 
Example 12
Project: Huochexing12306   File: PlatformGridView.java   View Source Code Vote up 4 votes
private LinearLayout getView(int position, OnClickListener ocL, Context context) {
			Bitmap logo;
			String label;
			OnClickListener listener;
			if (beans[position] instanceof Platform) {
				logo = getIcon((Platform) beans[position]);
				label = getName((Platform) beans[position]);
				listener = ocL;
			} else {
				logo = ((CustomerLogo) beans[position]).logo;
				label = ((CustomerLogo) beans[position]).label;
				listener = ((CustomerLogo) beans[position]).listener;
			}

			LinearLayout ll = new LinearLayout(context);
			ll.setOrientation(LinearLayout.VERTICAL);

			ImageView iv = new ImageView(context);
			int dp_5 = cn.sharesdk.framework.utils.R.dipToPx(context, 5);
			iv.setPadding(dp_5, dp_5, dp_5, dp_5);
			iv.setScaleType(ScaleType.CENTER_INSIDE);
			LinearLayout.LayoutParams lpIv = new LinearLayout.LayoutParams(
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			lpIv.setMargins(dp_5, dp_5, dp_5, dp_5);
			lpIv.gravity = Gravity.CENTER_HORIZONTAL;
			iv.setLayoutParams(lpIv);
			iv.setImageBitmap(logo);
			ll.addView(iv);

			TextView tv = new TextView(context);
//			tv.setTextColor(0x2A1E21);
			tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
			tv.setSingleLine();
			tv.setIncludeFontPadding(false);
			LinearLayout.LayoutParams lpTv = new LinearLayout.LayoutParams(
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			lpTv.gravity = Gravity.CENTER_HORIZONTAL;
			lpTv.weight = 1;
			lpTv.setMargins(dp_5, 0, dp_5, dp_5);
			tv.setLayoutParams(lpTv);
			tv.setText(Html.fromHtml("<font color='black'>"+label+"</font>"));
			ll.addView(tv);
			ll.setOnClickListener(listener);

			return ll;
		}