Android Studio||java改变xml布局layout/动态位置/imageview翻转对称/简单方法

step by step.

目录

1.layout改变实现动态(4次移动位置循环组成):

核心代码: 

整个代码: 

效果: 

 2. 平移实现动态

3.图片翻转对称


1.layout改变实现动态(4次移动位置循环组成):

核心代码: 

public void run() {
        RelativeLayout.LayoutParams temp = (RelativeLayout.LayoutParams) cat.getLayoutParams();
        temp.setMargins(0,270,0,0);
        cat.setRotation(10);
        cat.setLayoutParams(temp);
    }
}, t);

整个代码: 

public void keepRun(ImageView cat){
        int t = 0;
        for(int i=0;i<50;i++){
            run(cat,t);
            t+=800;
        }
    }
    public void run(ImageView cat,int t){
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                RelativeLayout.LayoutParams temp = (RelativeLayout.LayoutParams) cat.getLayoutParams();
                temp.setMargins(0,270,0,0);
                cat.setRotation(10);
                cat.setLayoutParams(temp);
            }
        }, t);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                RelativeLayout.LayoutParams temp = (RelativeLayout.LayoutParams) cat.getLayoutParams();
                temp.setMargins(0,270,0,0);
                cat.setLayoutParams(temp);
                cat.setRotation(0);
            }
        }, t+=200);//0.1秒后执行Runnable中的run方法
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                RelativeLayout.LayoutParams temp = (RelativeLayout.LayoutParams) cat.getLayoutParams();
                temp.setMargins(0,200,0,0);
                cat.setRotation(-10);
                cat.setLayoutParams(temp);
            }
        }, t+=200);//0.1秒后执行Runnable中的run方法
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                RelativeLayout.LayoutParams temp = (RelativeLayout.LayoutParams) cat.getLayoutParams();
                temp.setMargins(0,200,0,0);
                cat.setLayoutParams(temp);
                cat.setRotation(0);
            }
        }, t+=200);//0.1秒后执行Runnable中的run方法
    }

效果: 

Android Studio||java改变xml布局layout/动态位置/imageview翻转对称/简单方法_第1张图片Android Studio||java改变xml布局layout/动态位置/imageview翻转对称/简单方法_第2张图片

Android Studio||java改变xml布局layout/动态位置/imageview翻转对称/简单方法_第3张图片

Android Studio||java改变xml布局layout/动态位置/imageview翻转对称/简单方法_第4张图片

Android Studio||java改变xml布局layout/动态位置/imageview翻转对称/简单方法_第5张图片

 2. 平移实现动态

Android Studio||动态改变xml图片位置/旋转+平移/AnimationSet_bdy_y9的博客-CSDN博客这里写目录标题帧动画FrameAnimation补间动画TweenAnimationTranslatAnimation:平移动画ScaleAnimation:缩放动画alphaAnimation:淡出动画rotateAnimation:旋转动画setAnimation :动画集,可以包含多个动画Animator(属性动画):真正改变了动画的属性常见属性ValueAnimator:值动画PropertyValueHolder:多个动画同时执行帧动画FrameAnimation按字面理解,就是将多个图片连续。https://blog.csdn.net/weixin_51159944/article/details/129842687?spm=1001.2014.3001.5501

3.图片翻转对称

android:scaleX="-1"

//水平翻转 

安卓ImageView镜像翻转_imageview 镜像_u013394527的博客-CSDN博客android:scaleX = -1 可用来 水平镜像翻转android:scaleY = -1 可用来 垂直镜像翻转https://blog.csdn.net/u013394527/article/details/109131769?ops_request_misc=&request_id=&biz_id=102&utm_term=imageview%E7%BF%BB%E8%BD%AC&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-2-109131769.nonecase&spm=1018.2226.3001.4187

你可能感兴趣的:(scau,Android,android,studio,xml,android)