TextView 重力不适用于 API 18 或更高版本 [英] TextView gravity not working on API 18 or higher

查看:30
本文介绍了TextView 重力不适用于 API 18 或更高版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与其他视图重叠的 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
    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.

乐:

这个问题有没有解决办法?或者有谁知道为什么会这样?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆