Android-图形图像与动画之Animation实现图像的渐变、缩放、位移、旋转的代码

把代码过程重要的一些代码做个记录,下面代码是关于Android-图形图像与动画之Animation实现图像的 渐变、缩放、位移、旋转的代码。

成都创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、网站设计、宁蒗网络推广、小程序开发、宁蒗网络营销、宁蒗企业策划、宁蒗品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联公司为所有大学生创业者提供宁蒗建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
<Button
    android:id="@+id/button_scale"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="scale"
    android:layout_x="5dp"
    android:layout_y="383dp" />
<Button
    android:id="@+id/button_rotate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="rotate"
    android:layout_x="158dp"
    android:layout_y="383dp" />
<Button
    android:id="@+id/button_alpha"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="alpha"
    android:layout_x="5dp"
    android:layout_y="331dp" />
<Button
    android:id="@+id/button_translate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="translate"
    android:layout_x="160dp"
    android:layout_y="329dp" />
<Button
    android:id="@+id/button_alpha_translate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="alpha_translate"
    android:layout_x="84dp"
    android:layout_y="265dp" />

<ImageView
    android:id="@+id/imageview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="105dp"
    android:layout_y="133dp" 
    android:src="@drawable/ic_launcher"
    />
</AbsoluteLayout>

实现本实例的源代码如下:

public class Animations_Activity extends Activity {
    private Button button1;
    private Button button2;
    private Button button3;
    private Button button4;
    private Button button5;
    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animations_);
        button1=(Button)findViewById(R.id.button_alpha);
        button2=(Button)findViewById(R.id.button_rotate);
        button3=(Button)findViewById(R.id.button_scale);
        button4=(Button)findViewById(R.id.button_translate);
        button5=(Button)findViewById(R.id.button_alpha_translate);
        imageView=(ImageView)findViewById(R.id.imageview);
        button1.setOnClickListener(new MyButton());
        button2.setOnClickListener(new MyButton());
        button3.setOnClickListener(new MyButton());
        button4.setOnClickListener(new MyButton());
        button5.setOnClickListener(new MyButton());
    }
    class MyButton implements OnClickListener{

        @Override
        public void onClick(View arg0) {
            switch (arg0.getId()) {
            case R.id.button_alpha:
                Alpha();
                break;
            case R.id.button_rotate:
                Rotata();
                break;
            case R.id.button_scale:
                Scale();
                break;
            case R.id.button_translate:
                Translate();
                break;
            case R.id.button_alpha_translate:
                Alpha_Translate();
                break;

            default:
                break;
            }
        }

    }

    public void Alpha() {
        AnimationSet animationSet=new AnimationSet(true);
        AlphaAnimation alphaAnimation=new AlphaAnimation(1, 0);
        alphaAnimation.setDuration(2000);
        animationSet.addAnimation(alphaAnimation);
        imageView.startAnimation(animationSet);
    }
    public void Rotata(){
        AnimationSet animationSet=new AnimationSet(true);
        RotateAnimation rotateAnimation=new RotateAnimation(
                0, 360, 
                Animation.RELATIVE_TO_PARENT, 1f,
                Animation.RELATIVE_TO_PARENT, 0f);
        rotateAnimation.setDuration(2000);
        animationSet.addAnimation(rotateAnimation);
        imageView.startAnimation(animationSet);
    }
    public void Scale() {
        AnimationSet animationSet=new AnimationSet(true);
        ScaleAnimation scaleAnimation=new ScaleAnimation(
                1, 0.1f, 1, 0.1f, 
                Animation.RELATIVE_TO_SELF, 0.5f, 
                Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnimation.setDuration(2000);
        animationSet.addAnimation(scaleAnimation);
        imageView.startAnimation(scaleAnimation);
    }
    public void Translate() {
        AnimationSet animationSet=new AnimationSet(true);
        TranslateAnimation translateAnimation=new TranslateAnimation(
        translateAnimation.setDuration(2000);
        animationSet.addAnimation(translateAnimation);

        animationSet.setFillAfter(true);
        animationSet.setFillBefore(false);
        animationSet.setStartOffset(2000);
        animationSet.setRepeatCount(3);

        imageView.startAnimation(animationSet);
    }
    public void Alpha_Translate() {
        AnimationSet animationSet=new AnimationSet(true);
        AlphaAnimation alphaAnimation=new AlphaAnimation(1, 0);
        alphaAnimation.setDuration(2000);
        animationSet.addAnimation(alphaAnimation);
        TranslateAnimation translateAnimation=new TranslateAnimation(
        translateAnimation.setDuration(2000);
        animationSet.addAnimation(translateAnimation);
        imageView.startAnimation(animationSet);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_animations_, menu);
        return true;
    }

}

当前文章:Android-图形图像与动画之Animation实现图像的渐变、缩放、位移、旋转的代码
当前地址:https://www.cdcxhl.com/article12/ijsigc.html

成都网站建设公司_创新互联,为您提供营销型网站建设小程序开发微信公众号微信小程序企业建站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网页设计公司