android - 修复关于 `layout_marginHorizontal` 的 android studio 警告

标签 android android-layout android-support-library android-version

我在我的 android 版本中收到这些警告。

Warning:(19, 9) Attribute `layout_marginVertical` is only used in API level 26 and higher (current min is 24)
Warning:(20, 9) Attribute `layout_marginHorizontal` is only used in API level 26 and higher (current min is 24)
很明显,我们应用的布局使用了 layout_marginVerticallayout_marginHorizontal属性,它们是在 API 级别 26 中引入的。警告听起来好像这些属性在 24 级设备上不起作用,但它们确实可以完美运行。我想了解为什么我会收到这些警告,尽管似乎没有任何问题。
一个明显的解决方案是使用“速写”:marginTopmarginBottom而不是 marginVertical ,但我希望尽可能继续使用这些“短”参数,以提高可读性并减少重复。
这些属性是否在 24 级时没有记录?还是有某种向后兼容性在起作用?如果是这样,为什么会发出警告?
我们正在使用:
<uses-sdk
    android:minSdkVersion="24"
    android:targetSdkVersion="26" />

更新:设置targetSdkVersion="24"似乎修复了警告,并且所需的边距继续起作用。这解决了我的直接问题,但我对为什么 26 级功能在 24 级上起作用以及为什么以 26 级为目标会导致警告感到困惑。如果我想达到 26 级,我该怎么办?

最佳答案

这个 API 似乎是在 API 级别 26 中引入的。
由于您可能正在使用 AppCompatActivity,也许他们还为 pre 26 SDK 引入了一些向后兼容性。 Documentation

此外,您收到的警告可能只是 lint 检查错误。

关于android - 修复关于 `layout_marginHorizontal` 的 android studio 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49247301/

相关文章:

android - 在 CursorAdapter 中 bindView() 和 newView() 做了什么

android - 自定义按钮 : change style when pressed

java - 无法让android创建通知

android - 如何在 Android LinearLayout 周围创建边框?

安卓菜单标签

android - 是否需要导入 support-v4 和 appcompat-v7 才能使用它们?

java - 使用scaledBitmap创建透明度/镜像效果时避免致命内存错误

Android DataBinding & MVVM - 对不同布局文件夹中的布局文件使用相同的名称

android - Android Design Support Library 有哪些新功能以及如何使用它的 Snackbar?

android - 检索项目 : No resource found that matches the given name 'android:Widget.Material.Button.Colored' 的父项时出错