android studio ConstraintLayout杂记

1.match_parentwrap_content的区别。

  • 简单来说,match_parent相当于自适应手机屏幕大小,wrap_content是自适应对象大小,如textview即自适应文字的大小和数量。
  • 用法:android:layout_height="wrap_content"

2.ConstraintLayout约束布局可以实现多个层的叠加,使用也比较方便。

//控制绝对位置
app:layout_constraintHorizontal_bias="0.75"
app:layout_constraintVertical_bias="0.5"
//控制相对位移
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"

3.在代码里实现对目标对象位置的变化

//通过改变绝对位置实现对象位置变换
 ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) ImageView7.getLayoutParams();
 		//约束布局为ConstraintLayout.,其他布局方法换成对应的即可
  layoutParams.horizontalBias=(float) (0.25);//在水平方向为屏幕1/4处
  layoutParams.verticalBias=(float) (0.5);//在竖直方向为屏幕的1/2处
  ImageView7.setLayoutParams(layoutParams);

//通过改变相对位置实现对象位置移动
	ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) ImageView7.getLayoutParams();
			//注意改变的相对位置是整数,左和右只改变一个,零一个为0,如左右都改变10,则相当于没改变,上下同理。
	layoutParams.leftMargin =(int)10;
	layoutParams.rightMargin =0;
	layoutParams.topMargin = 0;
	layoutParams.bottomMargin = 10;
	ImageView7.setLayoutParams(layoutParams);

4.ConstraintLayout在代码里实现图片控件(imageview)的尺寸收缩、旋转、透明度变化

//旋转,angle为旋转的角度
mageView2.setRotation((float) angle);
//尺寸缩放ScaleX,ScaleY为缩放的比例
ImageView1.setScaleX((float)ScaleX);
ImageView1.setScaleY((float)ScaleY);
//透明度变化Alpha为透明度值
ImageView1.setAlpha((float)Alpha);



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值