I need to apply some constraints to a group of views in ConstraintLayout
. I want to group these views and continue editing while the layout designer in Android studio treats them as a single view. Is there a way to do so without actually wrapping the views with a ViewGroup
(another layout)? If such a wrapper is necessary, maybe there is a wrapper layout that comes with ConstraintLayout
and allows to group objects without creating heavy layouts like RelativeLayout
?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You can use
to group elements together.
Add a Guideline (vertical or horizontal) and then use that as an anchor for the other views. Here is a simple example of horizontally centering two grouped textviews: (showing design view in AS)
ConstraintLayout Chains
Android developers recently released a new version of
ConstraintLayout
(1.0.2 as of today). This version contains a new major feature - Chains, which allows us to group views inConstraintLayout
.Currently, you need to use the following gradle dependency to use this feature (since it is an alpha):
Here you may find the newest version of
ConstraintLayout
to use in your projects.Until Android Studio 2.3, Android Studio user interface designer did not support creating chains since you couldn't add bi-directional constraints in it. The solution was to create these constraints in manually XML, as mentioned by TranslucentCloud. From Android Studio 2.3 (currently only on canary channel), chains are supported in a UI editor as well (as GoRoS mentioned in comments).
Example
Following is an example of how to position two views together in the middle of a screen using
ConstraintLayout
and chains:Update (Jan, 2018) by @Mateus Gondim
In the recent versions, you should use
app:layout_constraintVertical_chainStyle="packed"
instead ofapp:layout_constraintVertical_chainPacked="true"