【问题标题】:Samsung devices rendering problems when changing text size三星设备在更改文本大小时出现渲染问题
【发布时间】:2015-10-23 20:22:00
【问题描述】:

在某些三星设备(API >= 21)上多次更改 TextView 字体大小后,字体呈现为矩形。

当 GPU 单元导致此异常时会出现问题:

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

复制行为的代码(来源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>

除了我找到的解决方案之外还有其他解决方案吗?

【问题讨论】:

    标签: java android text-rendering


    【解决方案1】:

    如果你遇到这个问题,那么我找到的解决方法是暂时将TextView的硬件加速改为软件加速。

    textView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    

    android:layerType="software"
    

    此解决方案解决了方形渲染问题,但是根据您的动画,您会注意到速度变慢的行为,并且根据文本大小还会丢失像素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-25
      • 1970-01-01
      • 1970-01-01
      • 2010-09-22
      • 1970-01-01
      • 2016-03-29
      • 1970-01-01
      • 2020-04-16
      相关资源
      最近更新 更多