如何使ConstraintLayout使用百分比值? [英] How to make ConstraintLayout work with percentage values?

查看:471
本文介绍了如何使ConstraintLayout使用百分比值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android Studio 2.2的Preview 1中,Google在其支持库中发布了新布局: ConstraintLayout .使用ConstraintLayout可以更轻松地在Android Studio中使用设计工具,但是我没有找到使用相对大小(如LinearLayout中的百分比或权重")的方法.有没有一种方法可以基于百分比定义约束?例如.使一个View占据屏幕的40%,在视图之间创建20%的边距,将一个View的宽度设置为另一个View宽度的50%?

With a Preview 1 of Android Studio 2.2 Google released a new layout in its support library: ConstraintLayout. With ConstraintLayout it is easier to use a Design tool in Android Studio, but I didn't find a way to use relative sizes (percents or 'weights' like in LinearLayout). Is there a way to define the constraints based on percents? E.g. make a View take 40% of a screen, create 20% margin between views, set a View's width to 50% of another View's width?

推荐答案

您目前可以通过两种方法来执行此操作.

You can currently do this in a couple of ways.

一种方法是创建辅助线(右键单击设计区域,然后单击添加垂直/水平辅助线).然后,您可以单击准则的标题"以将排名更改为基于百分比.最后,您可以将视图限制为准则.

One is to create guidelines (right-click the design area, then click add vertical/horizontal guideline). You can then click the guideline's "header" to change the positioning to be percentage based. Finally, you can constrain views to guidelines.

另一种方法是使用偏差(百分比)定位视图,然后将其他视图锚定到该视图.

Another way is to position a view using bias (percentage) and to then anchor other views to that view.

也就是说,我们一直在考虑如何提供基于百分比的尺寸.我无法做出任何承诺,但这是我们要补充的内容.

That said, we have been thinking about how to offer percentage based dimensions. I can't make any promise but it's something we would like to add.

这篇关于如何使ConstraintLayout使用百分比值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆