1
Android中TextView有最大文字大小嗎?Android textView錯誤? sp中的最大文字大小
我的應用程序必須在290sp左右顯示一些文本。但是,我發現某些設備無法顯示它,並且顯示了TextView的整個空白頁面。
在三星Galaxy Note 5(API 23)中,它的作品發現。 在Google Nexus 5(API 19)中,最大文字大小爲239sp。 在Samsung 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畫布上繪製文本。這樣,你不應該受到任何意外的限制 –
[字體大小太大,以適應緩存]可能重複(https://stackoverflow.com/questions/6253528/font-size-too-large-to-fit-in -cache) –