ConstraintLayout在开发中的一些好处

这种ui如果宽高定死,那么适配就不好,因为android手机的尺寸实在太多了。

一般做法:

采用线性布局,圆圈宽度使用权重,高度采用计算的方法

比如:

int picwidth = (ScreenUtils.getScreenWidthPx(base) - WonderfulDpPxUtils.dip2px(base, 151)) / 2;        

ViewGroup.LayoutParams layoutParams = rlCircleBgFlow.getLayoutParams();        

layoutParams.height = picwidth;

ConstraintLayout的做法:

ConstraintLayout有权重的属性,可以像线性布局一样适配屏幕,最主要的是他有一个宽高币的一个属性layout_constraintDimensionRatio,我们只要设置成1:1那就可以省去计算的方法了

如: android:layout_width="0dp"      

  android:layout_height="0dp"        

android:layout_marginLeft="@dimen/dp_10"      

  android:layout_marginBottom="@dimen/dp_50"      

  app:layout_constraintBottom_toTopOf="@id/iv_publish_close"        

app:layout_constraintDimensionRatio="1:1.2"      

  app:layout_constraintHorizontal_weight="1"        

app:layout_constraintLeft_toLeftOf="parent"        

app:layout_constraintRight_toLeftOf="@id/ll_push_project"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值