Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView is cut off when applying BlurMaskFilter

I want to blur the text of a TextView, but the text is cut off left and right.

Image of the cut off text

enter image description here

I tried to increase padding, margin. Changed gravity, Enabled/disabled font padding. Set a fixed height, lowered font size etc. All to the same result: The sides were cut off.

The setting of the mask filter is just two lines:

textView.paint.maskFilter = BlurMaskFilter(radius, BlurMaskFilter.Blur.NORMAL)
textView.postInvalidate()

This is how my XML layout looks like:

<TextView 
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="-1dp"              
    android:includeFontPadding="false"
    android:layerType="software"
    android:textSize="48sp"
    tools:textColor="@color/solid_white"
    tools:text="132" />

I'm looking for a solution to see the text fully without cutoffs on the edges.

like image 848
agz Avatar asked Dec 03 '25 16:12

agz


1 Answers

Remove this attribute from your <TextView> tag:

android:layerType="software"

Hardware acceleration is required for views to draw outside of their bounds. Note that padding doesn't help here because view contents are clipped by padding as well.

like image 152
Ben P. Avatar answered Dec 06 '25 07:12

Ben P.