如何在Android Studio中将视图添加到现有的链中

huangapple go评论79阅读模式
英文:

how to add a view to existing chain in android studios

问题

我正在Android Studio中创建单独的测试活动,因为我需要它们(在以后将这些测试合并到我的项目之前),所以我不得不定期添加更多按钮来启动新的活动,因为它们被添加进来。
我只找到了一个冗长的解决方法,即删除约束,创建一个新的链,并为每个项目重置约束(这是一个繁琐的过程,因为它们被约束到指南,所以每次都必须重置为0dp)。

尽管我在过去的几个月里尝试了IDE并在Google和StackOverflow上搜索了一些内容,但我无法找到一种简单地“添加到现有链”的方法。
即将(按钮)视图添加到垂直链的底部?

英文:

I am creating individual test activities in android studios as i need them (before combining these tests into my project at a later date) so I have to periodically add more buttons to start new activities as they are added.
I have only found a long workaround of removing constraints and creating a new chain and resetting the constraints for each item (a tedious process as they are constrained to guidelines, so each have to be reset to 0dp each time)

Despite my experimenting with the IDE over the last couple months and googling /seacrching stackOverflow, i cannot find a way to simply 'add to existing chain'
ie another (button) view to the bottom of a verical chain?

答案1

得分: 2

我不知道如何在设计窗口中执行此操作,但您始终可以使用XML打开代码窗口。思路是在约束两个视图的相邻边缘时,链会自动生成。在下面的示例中,两个TextView之间将出现链:

<TextView
    android:id="@+id/view_1"
    ...
    app:layout_constraintRight_toLeftOf="@+id/view_2"/>

<TextView
    android:id="@+id/view_2"
    ...
    app:layout_constraintLeft_toRightOf="@id/view_1"/>
英文:

I don't know how to do it using design window, but you always can open code window with XML. The idea is that chain automatically generates when you constraining neighboring sides of two views.
In the example below chain between two TextViews will appear:

    &lt;TextView
        android:id=&quot;@+id/view_1&quot;
        ...
        app:layout_constraintRight_toLeftOf=&quot;@+id/view_2&quot;/&gt;

    &lt;TextView
        android:id=&quot;@+id/view_2&quot;
        ...
        app:layout_constraintLeft_toRightOf=&quot;@id/view_1&quot;/&gt;

huangapple
  • 本文由 发表于 2020年1月3日 23:52:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/59581507.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定