After changing a TextView font size multiple times on some Samsung devices (with API >= 21), the font is rendered as rectangles.
The problem happens when the GPU unit is causing this exception:
10-23 14:14:36.590 1184-1243/com.android.testrendering E/Adreno-ES20: <TexSubImageLoad:405>: Texture miplevel doesn't exist. Returning GL_INVALID_OPERATION!
10-23 14:14:36.590 1184-1243/com.android.testrendering E/OpenGLRenderer: GL error: GL_INVALID_OPERATION
Code to replicate the behavior (source here ):
MainActivity.java
private int textSize = 50;
private int delta = 1;
private Runnable changeFontSize;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView textView = (TextView) findViewById(R.id.text);
textView.setText("qwertyuioplk,mjhnbgfvcdsxza1234567890");
final Handler mHandler = new Handler();
changeFontSize = new Runnable() {
@Override
public void run() {
textView.setTextSize(textSize);
textSize += delta;
if (textSize > 200) {
delta = -1;
}
if (textSize < 50) {
delta = 1;
}
mHandler.postDelayed(changeFontSize, 25);
}
};
changeFontSize.run();
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:id="@+id/text"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Any other solution than the one found by me?
If you experience this problem, then the solution I found was to temporarily change the hardware acceleration to software acceleration for the TextView.
textView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
or
android:layerType="software"
This solution solves the square rendering problem, however depending on your animation you will notice a slowing down behavior and depending on the text size also a lose of pixels.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.