Re: [问题] 各位觉得ConstraintLayout好用吗 ?

楼主: rexct (rexct)   2017-10-04 20:04:21
我是今年初才开始用ConstraintLayout 的新手,
觉得 ConstraintLayout 使用蛮直觉的,
不过都是直接在 xml 排位置,
在 Design 界面拖有时候会搞不定,
特别像是要制作 Chain 的时候。
会先在 Design 拖要用的元件,
之后再手动加上设定位置,像是
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view1"
遇到几个问题,
像是 match_parent 无效。
参考文件1有写到
在设定 android:layout_width 和 android:layout_height 时,
不能使用 match_parent,只能使用 wrap_content 和指定尺寸。
如果要有 match_parent 的效果,
可以设定
android:layout_width="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
比较特别的地方是制作 Chain
可以产生类似 LinearLayout 的串行
像是 A-B-C
主要就是每个物件中间都要有双方互连
A:
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/B"
B:
app:layout_constraintLeft_toRightOf="@+id/A"
app:layout_constraintRight_toLeftOf="@+id/C"
C:
app:layout_constraintLeft_toRightOf="@+id/B"
app:layout_constraintRight+toRightOf="parent"
排列的效果可以用 chainStyle 控制
app:layout_constrainHorizontal_chainStyle="packed"
分布同样可以用 weight 控制
layout_constraintHorizontal_weight
使用Chain 后就可以省掉在layout 内再使用 LinearLayout。
目前觉得比较不方便的点是如果已经有设定很多个相关位置的物件,
要改前面的物件还要顺便改有用到这个物件来定位的部份。
还有 include 还没试过。
参考文件1:
https://developer.android.com/training/constraint-layout/index.html
参考文件2:
https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html
缩: http://tinyurl.com/n26er43
作者: brandonron (假嗨)   2017-10-05 21:53:00
个人使用浅见,它可以解决你layout编排时候的,用较少的元件实现,如你的画面水平跟垂直的编排包裹太多层时,对app执行画面绘制时是一种负担。
作者: aiueoH (满满的)   2017-10-22 00:55:00
遇过app平台商要求render的效能,用constraint layout确实能够有明显的帮助
作者: zerofinal (人生~)   2017-11-14 17:44:00
推一个

Links booklink

Contact Us: admin [ a t ] ucptt.com