我在我的应用程序中有一些TextView,但是我不知道为什么android:gravity
属性在运行API 18+(4.3+)的设备上不能将文本内容居中。
这是我在自定义TextView
中使用的代码,它是RelativeLayout的子级:
<com.package.custom.CustomTextFont
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/seekbar"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/seekbar"
android:layout_marginLeft="@dimen/margin_tiny_double"
android:layout_toLeftOf="@+id/seekbar"
android:gravity="center_vertical|left"
android:paddingRight="@dimen/margin_tiny"
android:text="@string/text1"
android:textColor="@color/black"
android:textSize="@dimen/size_text_normal" />
这段代码应该将这个
TextView
的边缘与顶部和底部对齐,并将其放置在SeekBar
的左侧,这是有效的,但是TextView
会变大,因此使用android:gravity
将文本居中到中心并向左对齐。它有效,但我不知道为什么,在运行Android 4.3和4.4的设备上,文本没有居中对齐。这个问题可以在真实设备上以及Eclipse的布局预览(图形布局)上重现。是否有任何更改针对API 18+或
android:gravity
我错过了?PS:我在项目和AndroidManifest.xml中瞄准API 19
PS2:我的TextView是自定义的,只用于设置外部字体.tff
这是API 17-的外观:
这是API 18+的外观:
提前致谢!
=更新=
在我的清单中,我将
android:targetSdkVersion
从19更改为17,问题消失了,但这是一个“技巧”,而不是解决方案。如果这是API的问题,我该怎么办?是的,我有API 18和19的最新版本(今天,2014年1月30日)。