Java Code Examples for android.widget.TextView#getPaddingTop()

The following examples show how to use android.widget.TextView#getPaddingTop() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void onSharedElementStart(List<String> sharedElementNames,
                                 List<View> sharedElements,
                                 List<View> sharedElementSnapshots) {
    TextView author = getAuthor();
    targetTextSize = author.getTextSize();
    targetTextColors = author.getTextColors();
    targetPadding = new Rect(author.getPaddingLeft(),
            author.getPaddingTop(),
            author.getPaddingRight(),
            author.getPaddingBottom());
    if (IntentUtil.hasAll(intent,
            IntentUtil.TEXT_COLOR, IntentUtil.FONT_SIZE, IntentUtil.PADDING)) {
        author.setTextColor(intent.getIntExtra(IntentUtil.TEXT_COLOR, Color.BLACK));
        float textSize = intent.getFloatExtra(IntentUtil.FONT_SIZE, targetTextSize);
        author.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        Rect padding = intent.getParcelableExtra(IntentUtil.PADDING);
        author.setPadding(padding.left, padding.top, padding.right, padding.bottom);
    }
}
 
Example 2
@Override
public void onSharedElementStart(List<String> sharedElementNames,
                                 List<View> sharedElements,
                                 List<View> sharedElementSnapshots) {
    TextView author = getAuthor();
    targetTextSize = author.getTextSize();
    targetTextColors = author.getTextColors();
    targetPadding = new Rect(author.getPaddingLeft(),
            author.getPaddingTop(),
            author.getPaddingRight(),
            author.getPaddingBottom());
    if (IntentUtil.INSTANCE.hasAll(intent,
            IntentUtil.INSTANCE.getTEXT_COLOR(), IntentUtil.INSTANCE.getFONT_SIZE(), IntentUtil.INSTANCE.getPADDING())) {
        author.setTextColor(intent.getIntExtra(IntentUtil.INSTANCE.getTEXT_COLOR(), Color.BLACK));
        float textSize = intent.getFloatExtra(IntentUtil.INSTANCE.getFONT_SIZE(), targetTextSize);
        author.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        Rect padding = intent.getParcelableExtra(IntentUtil.INSTANCE.getPADDING());
        author.setPadding(padding.left, padding.top, padding.right, padding.bottom);
    }
}
 
Example 3
@Override
public void onSharedElementStart(List<String> sharedElementNames,
                                 List<View> sharedElements,
                                 List<View> sharedElementSnapshots) {
    TextView author = getAuthor();
    targetTextSize = author.getTextSize();
    targetTextColors = author.getTextColors();
    targetPadding = new Rect(author.getPaddingLeft(),
            author.getPaddingTop(),
            author.getPaddingRight(),
            author.getPaddingBottom());
    if (IntentUtil.hasAll(intent,
            IntentUtil.TEXT_COLOR, IntentUtil.FONT_SIZE, IntentUtil.PADDING)) {
        author.setTextColor(intent.getIntExtra(IntentUtil.TEXT_COLOR, Color.BLACK));
        float textSize = intent.getFloatExtra(IntentUtil.FONT_SIZE, targetTextSize);
        author.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        Rect padding = intent.getParcelableExtra(IntentUtil.PADDING);
        author.setPadding(padding.left, padding.top, padding.right, padding.bottom);
    }
}
 
Example 4
Source Project: ViewUtils   File: CenterDrawableHelper.java    License: Apache License 2.0 6 votes vote down vote up
private static void onCenterDraw(TextView view, Canvas canvas, Drawable drawable, int gravity) {
    int drawablePadding = view.getCompoundDrawablePadding();
    int ratio = 1;
    float total;
    switch (gravity) {
        case Gravity.RIGHT:
            ratio = -1;
        case Gravity.LEFT:
            total = view.getPaint().measureText(view.getText().toString()) + drawable.getIntrinsicWidth() + drawablePadding + view.getPaddingLeft() + view.getPaddingRight();
            canvas.translate(ratio * (view.getWidth() - total) / 2, 0);
            break;
        case Gravity.BOTTOM:
            ratio = -1;
        case Gravity.TOP:
            Paint.FontMetrics fontMetrics0 = view.getPaint().getFontMetrics();
            total = fontMetrics0.descent - fontMetrics0.ascent + drawable.getIntrinsicHeight() + drawablePadding + view.getPaddingTop() + view.getPaddingBottom();
            canvas.translate(0, ratio * (view.getHeight() - total) / 2);
            break;
    }
}
 
Example 5
private void chooseSize(PopupWindow pop, CharSequence text, TextView tv) {
	int wid = tv.getPaddingLeft() + tv.getPaddingRight();
	int ht = tv.getPaddingTop() + tv.getPaddingBottom();

	/*
	 * Figure out how big the text would be if we laid it out to the
	 * full width of this view minus the border.
	 */
	int cap = getWidth() - wid;
	if (cap < 0) {
		cap = 200; // We must not be measured yet -- setFrame() will fix it.
	}

	Layout l = new StaticLayout(text, tv.getPaint(), cap,
			Layout.Alignment.ALIGN_NORMAL, 1, 0, true);
	float max = 0;
	for (int i = 0; i < l.getLineCount(); i++) {
		max = Math.max(max, l.getLineWidth(i));
	}

	/*
	 * Now set the popup size to be big enough for the text plus the border.
	 */
	pop.setWidth(wid + (int) Math.ceil(max));
	pop.setHeight(ht + l.getHeight());
}
 
Example 6
Source Project: animation-samples   File: TextResize.java    License: Apache License 2.0 5 votes vote down vote up
private static Bitmap captureTextBitmap(TextView textView) {
    Drawable background = textView.getBackground();
    textView.setBackground(null);
    int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight();
    int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom();
    if (width == 0 || height == 0) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop());
    textView.draw(canvas);
    textView.setBackground(background);
    return bitmap;
}
 
Example 7
Source Project: animation-samples   File: TextResize.java    License: Apache License 2.0 5 votes vote down vote up
public TextResizeData(TextView textView) {
    this.paddingLeft = textView.getPaddingLeft();
    this.paddingTop = textView.getPaddingTop();
    this.paddingRight = textView.getPaddingRight();
    this.paddingBottom = textView.getPaddingBottom();
    this.width = textView.getWidth();
    this.height = textView.getHeight();
    this.gravity = textView.getGravity();
    this.textColor = textView.getCurrentTextColor();
}
 
Example 8
Source Project: atlas   File: TextResize.java    License: Apache License 2.0 5 votes vote down vote up
private static Bitmap captureTextBitmap(TextView textView) {
    Drawable background = textView.getBackground();
    textView.setBackground(null);
    int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight();
    int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom();
    if (width == 0 || height == 0) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop());
    textView.draw(canvas);
    textView.setBackground(background);
    return bitmap;
}
 
Example 9
Source Project: atlas   File: TextResize.java    License: Apache License 2.0 5 votes vote down vote up
public TextResizeData(TextView textView) {
    this.paddingLeft = textView.getPaddingLeft();
    this.paddingTop = textView.getPaddingTop();
    this.paddingRight = textView.getPaddingRight();
    this.paddingBottom = textView.getPaddingBottom();
    this.width = textView.getWidth();
    this.height = textView.getHeight();
    this.gravity = textView.getGravity();
    this.textColor = textView.getCurrentTextColor();
}
 
Example 10
Source Project: android-instant-apps   File: TextResize.java    License: Apache License 2.0 5 votes vote down vote up
private static Bitmap captureTextBitmap(TextView textView) {
    Drawable background = textView.getBackground();
    textView.setBackground(null);
    int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight();
    int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom();
    if (width == 0 || height == 0) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop());
    textView.draw(canvas);
    textView.setBackground(background);
    return bitmap;
}
 
Example 11
Source Project: android-instant-apps   File: TextResize.java    License: Apache License 2.0 5 votes vote down vote up
public TextResizeData(TextView textView) {
    this.paddingLeft = textView.getPaddingLeft();
    this.paddingTop = textView.getPaddingTop();
    this.paddingRight = textView.getPaddingRight();
    this.paddingBottom = textView.getPaddingBottom();
    this.width = textView.getWidth();
    this.height = textView.getHeight();
    this.gravity = textView.getGravity();
    this.textColor = textView.getCurrentTextColor();
}
 
Example 12
Source Project: android-login   File: TextSizeTransition.java    License: MIT License 5 votes vote down vote up
private static Bitmap captureTextBitmap(TextView textView) {
  Drawable background = textView.getBackground();
  textView.setBackground(null);
  int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight();
  int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom();
  if (width == 0 || height == 0) {
    return null;
  }
  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);
  canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop());
  textView.draw(canvas);
  textView.setBackground(background);
  return bitmap;
}
 
Example 13
Source Project: android-login   File: TextSizeTransition.java    License: MIT License 5 votes vote down vote up
public TextResizeData(TextView textView) {
  this.paddingLeft = textView.getPaddingLeft();
  this.paddingTop = textView.getPaddingTop();
  this.paddingRight = textView.getPaddingRight();
  this.paddingBottom = textView.getPaddingBottom();
  this.width = textView.getWidth();
  this.height = textView.getHeight();
  this.gravity = textView.getGravity();
  this.textColor = textView.getCurrentTextColor();
}
 
Example 14
Source Project: RichText   File: ImageTarget.java    License: MIT License 5 votes vote down vote up
int getReadHeight() {
    TextView tv = textViewWeakReference.get();
    if (tv == null) {
        return 0;
    }
    return tv.getHeight() - tv.getPaddingTop() - tv.getPaddingBottom();
}
 
Example 15
Source Project: RichText   File: AbstractImageLoader.java    License: MIT License 5 votes vote down vote up
private int getRealHeight() {
    TextView tv = textViewWeakReference.get();
    if (tv == null) {
        return 0;
    }
    return tv.getHeight() - tv.getPaddingTop() - tv.getPaddingBottom();
}
 
Example 16
Source Project: MaterialQQLite   File: ChatMsgAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void setBubble(TextView txtContent, ChatMsg chatMsg) {		
	Integer nOldBubble = (Integer)txtContent.getTag();
	if (null == nOldBubble || nOldBubble != chatMsg.m_nBubble) {
		int left = txtContent.getPaddingLeft();
        int right = txtContent.getPaddingRight();
        int top = txtContent.getPaddingTop();
        int bottom = txtContent.getPaddingBottom();

        boolean bIsUser = (ChatMsg.RIGHT == chatMsg.m_nType);
		boolean bUseDefBubble = true;
		
		if (chatMsg.m_nBubble != 0) {				
			//
		}
		
		if (bUseDefBubble) {
			if (bIsUser) {
				txtContent.setBackgroundResource(R.drawable.btn_style7);
				txtContent.setTextColor(0xFFFFFFFF);
                   txtContent.setTextIsSelectable(true);
				txtContent.setLinkTextColor(0xFF0000FF);
			} else {
				txtContent.setBackgroundResource(R.drawable.btn_style6);
				txtContent.setTextColor(0xFF000000);
                   txtContent.setTextIsSelectable(true);
				txtContent.setLinkTextColor(0xFF0000FF);
			}
			txtContent.setTag(0);
		}
		
		txtContent.setPadding(left, top, right, bottom);
	}
}
 
Example 17
protected void transplantStyle(TextView target, int resource) {
    //get styles from here
    TextView tv = (TextView)View.inflate(this, resource, null);
    int[] padding = {target.getPaddingLeft(), target.getPaddingTop(), target.getPaddingRight(), target.getPaddingBottom()};

    target.setTextColor(tv.getTextColors().getDefaultColor());
    target.setTypeface(tv.getTypeface());
    target.setBackgroundDrawable(tv.getBackground());
    target.setPadding(padding[0], padding[1], padding[2], padding[3]);
}
 
Example 18
/**
 * 改变外框大小,适应文字
 * 如果当前文字只有一行,则缩到外框适应文字大小
 * 如果文字有多行,则宽度不变,缩小高度到适应文字大小
 * 文字外框的位置不变
 *
 * @param view
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void adjustSize(TextView view) {
    if (view != null && view.getLayoutParams() != null) {
        /*
        //更好的实现方式,但是ios那边不支持这种方式
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        view.setLayoutParams(layoutParams);*/

        // 废弃的实现方式,使用WRAP_CONTENT最简单,且这种方式算出来的width有bug
        // @Deprecated
        /*int lineCount = Math.min(view.getLineCount(), getMaxLines(view));
        int width, height;
        if (lineCount > 1) {//多行,宽度不变,改变高度
            width = view.getWidth();
            height = view.getLineHeight() * lineCount + view.getPaddingTop() + view.getPaddingBottom();
        } else {//一行,改变宽度&高度
             Paint paint = view.getPaint();
            width = (int) paint.measureText(view.getText().toString()) + view.getPaddingLeft() + view.getPaddingRight();
            height = view.getLineHeight() + view.getPaddingTop() + view.getPaddingBottom();
        }*/

        int lineCount = Math.min(view.getLineCount(), getMaxLines(view));
        float width, height;
        if (lineCount > 1) {//多行,宽度不变,改变高度
            width = view.getWidth();
            height = view.getLineHeight() * lineCount + view.getPaddingTop() + view.getPaddingBottom();
        } else {//一行,改变宽度&高度
            width = view.getPaddingLeft() + Layout.getDesiredWidth(view.getText(), view.getPaint()) + view.getPaddingRight();
            height = view.getLineHeight() + view.getPaddingTop() + view.getPaddingBottom();
        }

        if (view.getLayoutParams() != null) {
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            layoutParams.width = (int) width;
            layoutParams.height = (int) height;
            view.setLayoutParams(layoutParams);
        }
    }
}