Remove space between stacked TextViews

后端 未结 8 1727
南旧
南旧 2020-12-09 02:27

I have a vertical LinearLayout with two TextView inside it. The former contains a static text property (it\'s text never change) and the last conta

8条回答
  •  时光说笑
    2020-12-09 03:20

    you should change the height of TextView and maybe change android:gravity="bottom"

    height is between textsize and size of textView with Wrapcontent.

    public class MyTextViewBounder extends TextView {
    public MyTextViewBounder(Context context) {
        super(context);
    }
    
    public MyTextViewBounder(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    public MyTextViewBounder(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    
    }
    
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    
        //test kích thước thực tế với kích thước của Textview bao quanh text của nó như thế nào
        int width, height;
        Paint iPaint;
        Rect  iRect = new Rect();
    
        iPaint = new Paint();
        iPaint.setTextSize(13);
        iPaint.setTextAlign(Paint.Align.CENTER);
    
        //call below code outsite
        //this.setText("Hung");
        //this.setTextSize(TypedValue.COMPLEX_UNIT_PX,13);
        //this..setIncludeFontPadding(false);   //height from 18px down to 15px
        iPaint.getTextBounds("Hung",0,4,iRect); //width = 34px, height = 12px
    
        width = this.getWidth(); //= 30px
        height = this.getHeight(); //= 18px
    
        width = this.getMeasuredWidth(); //=30px
        height = this.getMeasuredHeight(); //= 18px
    
        width = iRect.width();  //34px
        height = iRect.height(); //12 px
    
    }
    

    }

提交回复
热议问题