android - 为什么 Android Studio 正在删除和/或更改 layout_margin* 约束?

标签 android android-studio android-constraintlayout android-layout-editor

我正在使用 android.support.constraint.ConstraintLayout 来布局简单卡片的内容 View 。

我的 XML 每次都会随机更改:

  • 我切换到 Android Studio 布局编辑器的 Design 选项卡
  • 或者当我打开Preview Pane 时(在这种情况下,更改在我的更改过程中发生得更频繁)。

这些随机变化包括:

  • 删除我手动定义的布局边距(例如 layout_marginEnd)
  • 更改我手动输入的 margin 值
  • 添加 tools:layout_editor_absoluteX

问题:

  • 还有其他人体验过此 Android Studio 的功能吗?
  • 如何关闭此“功能”,以免破坏我的布局?
  • 在哪里向 Google 或 JetBrains 报告此错误?

请看一下这个文件差异,它是在切换到“设计”选项卡时自动生成的: Automatically made changes' diff in layout XML file

PS.: 我的Android Studio版本是2.2.3;我在 macOS Sierra 上运行它。

更新 #1

如建议的那样,在制作 layout_height="match_parent" 之后,我修改的次数减少了,但当我在 Layout Designer 中编辑布局时,我的 XML 仍然一团糟: Automatic changes #2 这次我想通过 Design UI 设置 layout_marginTop(选择的行是我想添加的),但我也得到了其他不需要的更改:

  • layout_marginStart 已移除;
  • app:layout_constraintBottom_toBottomOf 引用的 ID 有一个“+”号前缀,这意味着这些 ID 是新声明的,所以当我使用 Goto declaration 功能时,我必须从列表中选择它——这不是我想要的行为。
  • tools:layout_editor_absoluteX 被添加。我可以忽略它,但仍然 - 这不是我想要发生的事情。

最佳答案

在我的例子中,删除布局约束并再次添加它修复了消失的边距。

我使用的是 Android Studio 4.1.1。

关于android - 为什么 Android Studio 正在删除和/或更改 layout_margin* 约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41954472/

相关文章:

android - 为什么 Android 对 ConstraintLayout 使用单独的 xmlns

不带序列化的 Java 深度复制

android - 失败 [INSTALL_FAILED_OLDER_SDK] Android-L

android - 获取 JSON 并对其进行操作

android - Android Studio 1.4 中新的 content_xxxxx.xml 布局文件

android - ConstraintLayout,当约束依赖 View 消失时,布局 View 行为怪异

android - 如何在我的应用程序中使用 ScreenCap.cpp?

android - .append() 在使用 phonegap 时不起作用

android - Android Studio非常慢-几乎无法工作

android - ConstraintLayout 内可以链接多少个 View (添加关系)