安卓警告控件重叠 `Button-11` can overlap if …… grow due to localized text expansion

警告描述

在编写布局代码的时候,可能会弹出如下警告(@id表示控件id,@b,@c表示字符串)
Button-11 can overlap @id if @b,@c grow due to localized text expansion

含义

这个警告表示,如果@b和@c字符串变长了,可能会导致按钮与@id控件重叠。

解决方案

解决方法有两种,第一种,为使用@b和@c字符串的控件指定限定的宽度,而不是使用wrap_content。
第二种方案是直接忽略这个警告。
使用tools:ignore=“RelativeOverlap”,来忽略重叠警告。
使用tools,需要在根元素关联一个命名控件。

xmlns:tools="http://schemas.android.com/tools"

注意,tools 前缀只在开发环境中使用,不会对实际的运行应用程序产生影响。它仅用于辅助开发。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!--其他部分代码,多余的不写了-->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/revoke_once"
            tools:ignore="RelativeOverlap" />
</LinearLayout>

猜你喜欢

转载自blog.csdn.net/weixin_44499065/article/details/132130590