How to remove TextView top margin?

后端 未结 4 1977
日久生厌
日久生厌 2021-01-31 04:19

I do have a problem with TextView. I don\'t want to have any margin/padding above it.



        
相关标签:
4条回答
  • 2021-01-31 04:47

    Yes this space included by default. You are not able to remove that space as per my search area. So you need to have to implement some logic to have such view.

    See below Image:

    enter image description here

    Its not a good idea but you can do like below code:

        <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:background="#ffffff">
        <TextView android:layout_width="wrap_content"           
            android:layout_height="wrap_content"           
            android:id="@+id/ptp_hour"           
            android:textColor="@android:color/black"           
            android:textSize="100sp"
            android:lineSpacingMultiplier="0.8"
            android:scrollY="-100dp"
            android:scrollX="100dp"
            android:text="10"/>
        <TextView 
            android:text="10"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textColor="#00FFFFFF"
            android:shadowColor="#000000"
            android:shadowDy="-50"
            android:shadowRadius="1"
            android:textSize="100dp"/>
    
    </LinearLayout>
    

    Here, first "10" is of your properties and second one is as i have set for you.

    Enjoy. :))

    0 讨论(0)
  • 2021-01-31 04:50

    using android:includeFontPadding="false" helped me a lot in a similar situation.

    0 讨论(0)
  • 2021-01-31 04:51

    I had the same issue where setting android:includeFontPadding=false did not help. The best solution I could find in reasonable time was to override the TextView's onDraw method and to adjust the canvas for the difference between the font metrics' top and ascent values:

    FontMetricsInt fontMetricsInt;
    @Override
    protected void onDraw(Canvas canvas) {
        if (adjustTopForAscent){
            if (fontMetricsInt == null){
                fontMetricsInt = new FontMetricsInt();
                getPaint().getFontMetricsInt(fontMetricsInt);
            }
            canvas.translate(0, fontMetricsInt.top - fontMetricsInt.ascent);
        }
        super.onDraw(canvas);
    }
    
    0 讨论(0)
  • 2021-01-31 04:58

    What you need to do is to put the other view relative to the top of the font, and give it a negative android:layout_marginBottom in dip, such that it matches the top of the font. If the font has a margin, I don't think there is a better way of doing it.

    0 讨论(0)
提交回复
热议问题