Android文本视图错误?sp中的最大文本大小

Android文本视图错误?sp中的最大文本大小,android,textview,Android,Textview,Android中的TextView有最大文本大小吗 我的应用程序必须在290sp左右显示一些文本。但是,我发现一些设备无法显示它,并且显示了一个完整的空白页面,即TextView 在三星Galaxy Note 5(API 23)中,它可以工作。 在GoogleNexus5(API 19)中,最大文本大小为239sp。 在三星Galaxy S7(API 23)中,最大文本大小为179sp 下面是我的演示代码: 布局XML <?xml version="1.0" encoding="utf-8

Android中的TextView有最大文本大小吗

我的应用程序必须在290sp左右显示一些文本。但是,我发现一些设备无法显示它,并且显示了一个完整的空白页面,即TextView

在三星Galaxy Note 5(API 23)中,它可以工作。 在GoogleNexus5(API 19)中,最大文本大小为239sp。 在三星Galaxy S7(API 23)中,最大文本大小为179sp

下面是我的演示代码: 布局XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.xxx.texttutorial.MainActivity">
    <Button
        android:id="@+id/buttonPlus"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="+10"/>
    <TextView
        android:id="@+id/textViewCurrentTextSize"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/buttonPlus"
        android:text="130"
        android:gravity="center_horizontal"
        android:textSize="40sp"
        />
    <Button
        android:id="@+id/buttonMinus"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/textViewCurrentTextSize"
        android:text="-10"
        />
    <TextView
        android:id="@+id/currentText"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/textViewCurrentTextSize"
        android:textSize="130sp"
        android:gravity="center"
        android:text="X"/>
</RelativeLayout>

由于屏幕密度像素,请尝试在值资源文件中为不同的屏幕分辨率分配不同的文本大小。请阅读

我试过这么大的一篇文章。不知道是否有任何限制,但知道可能的解决方案。您可能不必使用TextView,而是直接在view.s画布上绘制文本。这样,你就不会遭受任何意外的限制
public class MainActivity extends AppCompatActivity {

  int textSize = 130;

  TextView currentText, textViewCurrentTextSize;

  @Override

  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);


    currentText = (TextView)findViewById(R.id.currentText);
    textViewCurrentTextSize = (TextView)findViewById(R.id.textViewCurrentTextSize);
    (findViewById(R.id.buttonPlus)).setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        textSize += 10;
        currentText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
        textViewCurrentTextSize.setText(textSize+"");
      }
    });
    (findViewById(R.id.buttonMinus)).setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        textSize -= 10;
        currentText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
        textViewCurrentTextSize.setText(textSize+"enter code here");
      }
    });
  }
}