【发布时间】:2017-06-11 14:31:28
【问题描述】:
Android 中的 TextView 是否有最大文本大小?
我的应用程序必须在 290sp 左右显示一些文本。但是,我发现某些设备无法显示它,并且显示了整个空白页面是 TextView。
在三星 Galaxy Note 5 (API 23) 中,它可以找到。 在 Google Nexus 5 (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>
MainActivity JAVA
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");
}
});
}
}
【问题讨论】:
-
有新人尝试过这么大的文字。并且不知道是否有任何限制,但知道可能的解决方案。您可能不必使用 TextView,而是直接在 view.s 画布上绘制文本。这样你就不会受到任何意想不到的限制