1.match_parent
与wrap_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);