android - 在 View 级别抑制 lint 警告

标签 android maven suppress-warnings lint

我从 lint 收到以下错误:InconsistentLayout。有时这是预期的,因为平板电脑和手机布局不同。这就是 lint 警告的最后几句话的原因:

There are cases where this is intentional. For example, you may have a dedicated large tablet layout which adds some extra widgets that are not present in the phone version of the layout. As long as the code accessing the layout resource is careful to handle this properly, it is valid. In that case, you can suppress this lint check for the given extra or missing views, or the whole layout

完美,我同意。我想抑制警告,但只针对我得到的特定 View ,而不是针对包含它的整个布局(以避免隐藏无意的错误)。我通常在 Maven 在构建时使用的项目中的 lint.xml 文件中配置 lint 抑制警告。

我像这样抑制布局级别的警告:

<?xml version="1.0" encoding="UTF-8"?>
<lint>
    <issue id="InconsistentLayout" >

        <ignore path="res/layout/my_layout.xml" />
    </issue>
</lint>

我如何声明 lint 只忽略我验证过的 View ID 是否不一致?

最佳答案

将以下属性添加到 View :

tools:ignore="InconsistentLayout"

并添加命名空间前缀声明

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

到 View 元素或其父元素之一。

进一步阅读:http://developer.android.com/tools/debugging/improving-w-lint.html#src

关于android - 在 View 级别抑制 lint 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19004144/

相关文章:

android - PhoneGap+Cordova 应用程序无法在 AVD(Android 虚拟设备)上运行

android - 从 SD 卡安装 APK 无文件浏览器 Android 手机

android - Lollipop 的 backgroundTint 对 Button 没有影响

java - 在 Maven 中,如何引用文件系统上该位置不存在的父 pom?

maven - gradle init不适用于pom.xml中的某些插件

php - 防止 LDAP 函数出现 PHP 警告

linq-to-sql - 抑制 LINQ to SQL DBML 警告

android - 动画 View 的 OnclickListener

java - RabbitMQ SLF4J : Failed to load class "org.slf4j.impl.StaticLoggerBinder"

groovy - 在 Groovy 中抑制警告 “Access to field exceeds its access rights”