ConstraintLayout编辑器有偏 [英] ConstraintLayout Editor Biased
问题描述
我一直在尝试为我的应用制作GUI(使用ConstraintLayout),其中我的图像的行为类似于对齐的按钮,但是,即使我移动(并保存),这些按钮(或其他任何东西)也存在这个奇怪的问题)约束位置,它只是返回到某个数字(在本例中为16).
I've been trying to make a GUI for my app (using ConstraintLayout) where I have images that act like buttons aligned, however, those buttons (or anything actually) have this weird issue where even if I move (and save) the constraint position, it just goes back to some number (in this case 16).
我在这里做错了什么?是什么原因/为什么编辑器要重置位置?
What am I doing wrong here? What causes this/Why is the editor resetting the position?
http://i.imgur.com/OFndFb7.gifv (GIF-40s )
http://i.imgur.com/OFndFb7.gifv (GIF - 40s)
版本:
- Android版ConstraintLayout-1.0.2版
- Android Studio-2.3.3#AI-162.4069837
布局的XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="25dp"
tools:layout_editor_absoluteX="0dp">
<Button
android:id="@+id/Button_Color_Red"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="80dp"
android:layout_marginStart="16dp"
android:background="@drawable/btn_red_color_menu"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
<Button
android:id="@+id/Button_Color_Indigo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="80dp"
android:layout_marginStart="8dp"
android:background="@drawable/btn_indigo_color_menu"
app:layout_constraintLeft_toRightOf="@+id/Button_Color_Yellow"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/Button_Color_Green"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="80dp"
android:layout_marginStart="8dp"
android:background="@drawable/btn_green_color_menu"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@+id/Button_Color_Indigo"/>
<Button
android:id="@+id/Button_Color_Yellow"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="80dp"
android:layout_marginStart="8dp"
android:background="@drawable/btn_yellow_color_menu"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@+id/Button_Color_Red" />
</android.support.constraint.ConstraintLayout>
btn_x_color_menu的XML:
XML for btn_x_color_menu:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/Red_Primary"/>
</shape>
</item>
</selector>
推荐答案
按钮Button_Color_Green
上有两个冲突的属性.
There are two attributes on the button Button_Color_Green
that are in conflict.
android:layout_marginLeft="16dp"
android:layout_marginStart="8dp"
设计器在您移动按钮时创建android:layout_marginLeft
,但是android:layout_marginStart
保持不变并且发生冲突.这就是为什么移动小部件后边距会恢复的原因.
The designer creates android:layout_marginLeft
when you move the button, but android:layout_marginStart
remains unchanged and in conflict. That is why the margin reverts after you move the widget.
这两个属性对于从左到右的布局应该是相同的,但是设计者似乎想更改android:layout_marginLeft
,但是尊重android:layout_marginStart
(如果存在的话).
These two attributes should be the same for a left-to-right layout, but the designer seems to want to change android:layout_marginLeft
but honors android:layout_marginStart
if it is present.
这可能是ConstraintLayout
1.0.2中的错误.在找到修复或更好的解决方案之前,您可以手动将这些属性更改为相同,或者仅使用android:layout_marginLeft
并在以后手动添加回android:layout_marginStart
. (皮棉应该提醒您这样做.)
This may be a bug in ConstraintLayout
1.0.2. Until a fix or better solution is found, you can just manually change these attributes to be the same or just use android:layout_marginLeft
and manually add android:layout_marginStart
back in at a later time. (Lint should remind you to do this.)
现在您知道问题所在了,您也许可以找到更好的解决方案.
Now that you know the issue, you may be able to work out a better solution.
我希望这会有所帮助.
这篇关于ConstraintLayout编辑器有偏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!