1.遇到一個(gè)很奇怪的兼容問(wèn)題酪惭,EditText中輸入的文字在部分努比亞手機(jī)上無(wú)法居中,其他手機(jī)無(wú)此問(wèn)題。布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="Hello World!"
android:inputType="text"
android:maxLines="1" />
</LinearLayout>
2.實(shí)際顯示效果:
3.解決方法:
在代碼中設(shè)置文字對(duì)齊方式(在布局文件中設(shè)置textAlignment是無(wú)效的):
EditText editText = findViewById(R.id.textview);
editText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
4.修改后效果: