不能形成Android Studio中

问题描述:

两个视图/小部件之间的链条,我尽量让的EditText查看之间的链(双向约束)按钮查看使用约束锚,它不会产生链。不能形成Android Studio中

它只是制约了,如果我试图约束一个查看到另一个。

我试图将EditText的右侧链接到按钮的左侧。

这是我的布局编辑器的样子:

Layout Editor

+3

这个android教程太可怕了。他们排除了很多步骤,按钮不在他们说的地方,按顺序不按他们应该说的方式工作......很令人沮丧。有人需要编写关于如何使用本教程的教程。如果有人找到更好的选择,请发布。 – segFaultCoder

+0

同样的问题在这里...目前看来你必须选择两个视图后使用“中心水平”选项。也许它是版本? –

我试图弄清楚这一点了。我发现一种方法是选择两个视图,然后右键单击并选择Center Horizo​​ntally。这会创建链条,但是您必须相应地调整任何其他约束条件。我是Android的新手,所以我确信会有其他方法......

我有同样的问题。按照本教程的指示进入XML: https://developer.android.com/training/basics/firstapp/building-ui.html

在教程上,单击“查看最终布局XML”并进行比较。我的XML丢失:

app:layout_constraintLeft_toRightOf="@+id/editText" 

我通过在蓝图模式下创建链来解决此问题。该教程从来没有说你必须回到它,但如果你这样做,你可以创建链。

+0

你是怎么做到的?我处于蓝图模式,但锚点未连接(未显示绿色) – mukulg

通过在两个编辑文本添加约束解决(APP:layout_constraintRight_toLeftOf = “@ + ID /键”)和按钮(应用程序:layout_constraintBaseline_toBaselineOf = “@ + ID/EDITTEXT”)

完整示例如下

<EditText 
    android:id="@+id/editText" 
    android:layout_width="245dp" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="16dp" 
    android:layout_marginStart="16dp" 
    android:ems="10" 
    app:layout_constraintRight_toLeftOf="@+id/button" 
    android:hint="@string/edit_message" 
    android:inputType="textPersonName" 
    app:layout_constraintLeft_toLeftOf="parent" 
    android:layout_marginTop="16dp" 
    app:layout_constraintTop_toTopOf="parent" /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:layout_marginRight="16dp" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintBaseline_toBaselineOf="@+id/editText" 
    app:layout_constraintLeft_toRightOf="@+id/editText" 
    android:layout_marginLeft="16dp" /> 

我认为android studio ui编辑器需要更多的改进来创建链,目前我正在使用Android Studio Preview 3。0金丝雀3

有时从编辑器它完美,但有时它不是,当链接无法从UI编辑器发生,我们需要手动添加约束按要求水平或垂直链以下是制约

layout_constraintTop_toTopOf 
layout_constraintTop_toBottomOf 
layout_constraintBottom_toTopOf 
layout_constraintBottom_toBottomOf 
layout_constraintBaseline_toBaselineOf 
layout_constraintStart_toEndOf 
layout_constraintStart_toStartOf 
layout_constraintEnd_toStartOf 
layout_constraintEnd_toEndOf 

,也我们在XML手动声明链风格遵循

layout_constraintHorizo​​ntal_chainStyle或layout_constraintVertical_chainStyle

CHAIN_SPREAD-- the elements will be spread out (default style)

加权链-- in CHAIN_SPREAD mode, if some widgets are set to MATCH_CONSTRAINT, they will split the available space

CHAIN_SPREAD_INSIDE-- similar, but the endpoints of the chain will not be spread out

CHAIN_PACKED-- the elements of the chain will be packed together. The horizontal or vertical bias attribute of the child will then affect the positioning of the packed elements

希望机器人工作室编辑器将提高这一

我已经能够在蓝图布局中创建链式视图的方式是通过拖动单击,选择要链接的对象。然后当他们被选中时,右键单击并选择“水平居中”。完成后,我可以创建其他约束和链接

接下来的教程只是提示,以确保Android Studio是最新的。我想知道在按照教程时某些按钮的位置,但发现我使用的是旧版本。

在这个问题上,最好的是James @ 6/6/17。

  1. 添加三个按钮,在视图中
  2. 它们全部选中,然后右键单击
  3. 选择“水平居中”

但这招打造链

我不服从打开Autoconnect教程(因为我正在尝试所有内容)。

我选择了两个小部件,然后选择了Center Horizo​​ntally。链条创建完成后,我将Autoconnect关闭,然后继续教程。

我得到了一个解决方案,可能不会是最好的一个,直到有人真正回答,但工作。 我希望这可以帮助那些和我在同一个地方的人,这样你就可以继续工作。

看起来像android工作室的界面不能正常工作时来创建链。来自这里的人的一些选项适用于2或3个元素,但我有5个元素。

所以答案就是在代码XML中解决这个问题。

我的步骤是水平安排,如果你想垂直只是改变向左/右顶部/底部

我把,我要和删除所有连接处的所有元素。 (比我的情况,我连接顶部和底部,所以他们可以在中间

然后我连接左边的第一个元素和右边的最后一个元素。 并连接下一个元素左侧的每个元素的右侧。

app:layout_constraintRight_toLeftOf="@id/right_element"

Image of elements connect normal, no chain yet

之后,我去里面的代码并手动将向左元素的连接。

app:layout_constraintLeft_toRightOf="@+id/left_element"

而且已创建。 Image of elements connect with chain

我希望这个帮助,抱歉不要张贴图片,我没有足够的声誉,但XD。

DESIGN选项卡非常容易出错! 只要做你想在设计中做的事情,但是通过XML来写。无需教程,它是不言自明的,连接所有的左派和权利!

我之前有同样的问题,而且从我所能告诉的我们有同样的问题。

本教程希望您使用android studio 3版本。当我得到这个问题时,我意识到我的android studio仍然是2.2.3。将版本3和sdk等的更新安装到最新版本后,它就可以工作了。

希望这会有所帮助。