TextView重力不适用于API 18或更高版本 [英] TextView gravity not working on API 18 or higher
问题描述
我有一个与其他视图重叠的TextView.一切正常,除了API的引力等于或大于18之外.
I have an TextView wich overlaps some other view. Everything works great, except the gravity on API equal or higher than 18.
这是我的TextView:
Here is my TextView:
<TextView
android:id="@+id/overlappingTextView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignBottom="@id/behindLinearLayout"
android:layout_alignLeft="@id/behindLinearLayout"
android:layout_alignRight="@id/behindLinearLayout"
android:layout_alignTop="@id/behindLinearLayout"
android:background="@drawable/overlapping_bg"
android:gravity="center"
android:text="Waiting for user confirmation..."
android:textColor="@color/blue" />
重力在4.2.2或更低版本上可以正常运行,但在4.3或更高版本上则无法运行...它仅部分起作用,它居中,但只能垂直.
The gravity works ok on 4.2.2 or lower but is not working on 4.3 and higher ... It works only partially, it is centered but only vertically.
LE:
没有解决此问题的方法?还是有人知道为什么会这样?
There is no fix for this issue? Or does anyone know why this is happening?
推荐答案
这似乎是API 18+中的一个已知问题,并且存在一种变通方法,涉及将您的视图包装在LinearLayout中.
This appears to be a known issue in API 18+, and there's a workaround involving wrapping your view in a LinearLayout.
在此线程中查看答案.
在您的情况下,固定代码应类似于:
In your case, the fixed code should look something like:
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_alignBottom="@id/behindLinearLayout"
android:layout_alignLeft="@id/behindLinearLayout"
android:layout_alignRight="@id/behindLinearLayout"
android:layout_alignTop="@id/behindLinearLayout"
android:background="@drawable/overlapping_bg" >
<TextView
android:id="@+id/overlappingTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Waiting for user confirmation..."
android:textColor="@color/blue" />
</LinearLayout>
这篇关于TextView重力不适用于API 18或更高版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!