码迷,mamicode.com
首页 > 其他好文 > 详细

按钮点击,弹出三个按钮

时间:2017-05-21 00:21:44      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:ota   import   animator   atm   wrap   ant   app   tar   example   


<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.z.testz.fangmeipuxiaoguo.FangmeipuActivity"> <!--<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/colorAccent" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" >--> <ImageView android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:id="@+id/icon1" android:src="@drawable/shizi" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:id="@+id/icon2" android:src="@drawable/shizi" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:id="@+id/icon3" android:src="@drawable/shizi" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:id="@+id/imagebutton_bottom" android:src="@drawable/shizi" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <!-- </RelativeLayout>--> </RelativeLayout>

 

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.AppCompatButton;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.z.testz.R;


public class FangmeipuActivity extends AppCompatActivity {

    private ImageView button;
    private int count= 0;
    private ImageView icon1;
    private ImageView icon2;
    private ImageView icon3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fangmeipu);

        button = (ImageView) findViewById(R.id.imagebutton_bottom);
        icon1 = (ImageView) findViewById(R.id.icon1);
        icon2 = (ImageView) findViewById(R.id.icon2);
        icon3 = (ImageView) findViewById(R.id.icon3);



        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(count%2==0){
                    open();
                    openMain();
                    count++;
                } else{
                    close();
                    closeMain();
                    count++;
                }

            }
        });

        icon1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
                closeMain();
                count=0;
                Toast.makeText(FangmeipuActivity.this, "按钮1被选择了", Toast.LENGTH_SHORT).show();
            }
        });
        icon2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
                count=0;
                closeMain();
                Toast.makeText(FangmeipuActivity.this, "按钮2被选择了", Toast.LENGTH_SHORT).show();
            }
        });
        icon3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                close();
                closeMain();
                count=0;
                Toast.makeText(FangmeipuActivity.this, "按钮3被选择了", Toast.LENGTH_SHORT).show();
            }
        });



    }
        private void openMain() {
            ObjectAnimator anim = ObjectAnimator.ofFloat(button, "rotation", 0f, 90f);
            anim.setDuration(1000);
            anim.setRepeatMode(ValueAnimator.RESTART);

            anim.setRepeatCount(0);
            anim.start();
        }
        private void closeMain() {
            ObjectAnimator anim = ObjectAnimator.ofFloat(button, "rotation", 0f, -90f);
            anim.setDuration(1000);
            anim.setRepeatMode(ValueAnimator.RESTART);

            anim.setRepeatCount(0);
            anim.start();
        }
        private void open() {

        ObjectAnimator icon1Anim_scaley=ObjectAnimator.ofFloat(icon1,"scaleY",0.1f,0,0.5f,1);
        icon1Anim_scaley.setDuration(1000);
        icon1Anim_scaley.setRepeatCount(0);
        icon1Anim_scaley.setRepeatMode(ValueAnimator.RESTART);
        icon1Anim_scaley.start();
        ObjectAnimator icon1Anim_scalex=ObjectAnimator.ofFloat(icon1,"scaleX",0.1f,0,0.5f,1);
        icon1Anim_scalex.setDuration(1000);
        icon1Anim_scalex.setRepeatCount(0);
        icon1Anim_scalex.setRepeatMode(ValueAnimator.RESTART);
        icon1Anim_scalex.start();
        ObjectAnimator icon1Anim=ObjectAnimator.ofFloat(icon1,"translationY",-300);
        icon1Anim.setDuration(1000);
        icon1Anim.setRepeatMode(ValueAnimator.RESTART);
        icon1Anim.setRepeatCount(0);
        icon1Anim.start();

        ObjectAnimator icon2Anim=ObjectAnimator.ofFloat(icon2,"translationY",-300);
        ObjectAnimator icon2Anim_x=ObjectAnimator.ofFloat(icon2,"translationX",-300);
        icon2Anim.setDuration(1000);
        icon2Anim_x.setDuration(1000);
        icon2Anim.setRepeatMode(ValueAnimator.RESTART);
        icon2Anim_x.setRepeatMode(ValueAnimator.RESTART);
        icon2Anim.setRepeatCount(0);
        icon2Anim_x.setRepeatCount(0);
        icon2Anim.start();
        icon2Anim_x.start();
        ObjectAnimator icon2Anim_scaley=ObjectAnimator.ofFloat(icon2,"scaleY",0.1f,0,0.5f,1);
        icon2Anim_scaley.setDuration(1000);
        icon2Anim_scaley.setRepeatCount(0);
        icon2Anim_scaley.setRepeatMode(ValueAnimator.RESTART);
        icon2Anim_scaley.start();
        ObjectAnimator icon2Anim_scalex=ObjectAnimator.ofFloat(icon2,"scaleX",0.1f,0,0.5f,1);
        icon2Anim_scalex.setDuration(1000);
        icon2Anim_scalex.setRepeatCount(0);
        icon2Anim_scalex.setRepeatMode(ValueAnimator.RESTART);
        icon2Anim_scalex.start();

        ObjectAnimator icon3Anim=ObjectAnimator.ofFloat(icon3,"translationY",-300);
        ObjectAnimator icon3Anim_x=ObjectAnimator.ofFloat(icon3,"translationX",300);
        icon3Anim.setDuration(1000);
        icon3Anim_x.setDuration(1000);
        icon3Anim.setRepeatMode(ValueAnimator.RESTART);
        icon3Anim_x.setRepeatMode(ValueAnimator.RESTART);
        icon3Anim.setRepeatCount(0);
        icon3Anim_x.setRepeatCount(0);
        icon3Anim.start();
        icon3Anim_x.start();
        ObjectAnimator icon3Anim_scaley=ObjectAnimator.ofFloat(icon3,"scaleY",0.1f,0,0.5f,1);
        icon3Anim_scaley.setDuration(1000);
        icon3Anim_scaley.setRepeatCount(0);
        icon3Anim_scaley.setRepeatMode(ValueAnimator.RESTART);
        icon3Anim_scaley.start();
        ObjectAnimator icon3Anim_scalex=ObjectAnimator.ofFloat(icon3,"scaleX",0.1f,0,0.5f,1);
        icon3Anim_scalex.setDuration(1000);
        icon3Anim_scalex.setRepeatCount(0);
        icon3Anim_scalex.setRepeatMode(ValueAnimator.RESTART);
        icon3Anim_scalex.start();

    }
    private void close() {
        ObjectAnimator icon1Anim_scaley=ObjectAnimator.ofFloat(icon1,"scaleY",1,1,0.5f,0);
        icon1Anim_scaley.setDuration(1000);
        icon1Anim_scaley.setRepeatCount(0);
        icon1Anim_scaley.setRepeatMode(ValueAnimator.RESTART);
        icon1Anim_scaley.start();
        ObjectAnimator icon1Anim_scalex=ObjectAnimator.ofFloat(icon1,"scaleX",1,1,0.5f,0);
        icon1Anim_scalex.setDuration(1000);
        icon1Anim_scalex.setRepeatCount(0);
        icon1Anim_scalex.setRepeatMode(ValueAnimator.RESTART);
        icon1Anim_scalex.start();
        ObjectAnimator icon1Anim=ObjectAnimator.ofFloat(icon1,"translationY",0);
        icon1Anim.setDuration(1000);
        icon1Anim.setRepeatMode(ValueAnimator.RESTART);
        icon1Anim.setRepeatCount(0);
        icon1Anim.start();

        ObjectAnimator icon2Anim=ObjectAnimator.ofFloat(icon2,"translationY",0);
        ObjectAnimator icon2Anim_x=ObjectAnimator.ofFloat(icon2,"translationX",0);
        icon2Anim.setDuration(1000);
        icon2Anim_x.setDuration(1000);
        icon2Anim.setRepeatMode(ValueAnimator.RESTART);
        icon2Anim_x.setRepeatMode(ValueAnimator.RESTART);
        icon2Anim.setRepeatCount(0);
        icon2Anim_x.setRepeatCount(0);
        icon2Anim.start();
        icon2Anim_x.start();
        ObjectAnimator icon2Anim_scaley=ObjectAnimator.ofFloat(icon2,"scaleY",1,1,0.5f,0);
        icon2Anim_scaley.setDuration(1000);
        icon2Anim_scaley.setRepeatCount(0);
        icon2Anim_scaley.setRepeatMode(ValueAnimator.RESTART);
        icon2Anim_scaley.start();
        ObjectAnimator icon2Anim_scalex=ObjectAnimator.ofFloat(icon2,"scaleX",1,1,0.5f,0);
        icon2Anim_scalex.setDuration(1000);
        icon2Anim_scalex.setRepeatCount(0);
        icon2Anim_scalex.setRepeatMode(ValueAnimator.RESTART);
        icon2Anim_scalex.start();

        ObjectAnimator icon3Anim=ObjectAnimator.ofFloat(icon3,"translationY",0);
        ObjectAnimator icon3Anim_x=ObjectAnimator.ofFloat(icon3,"translationX",0);
        icon3Anim.setDuration(1000);
        icon3Anim_x.setDuration(1000);
        icon3Anim.setRepeatMode(ValueAnimator.RESTART);
        icon3Anim_x.setRepeatMode(ValueAnimator.RESTART);
        icon3Anim.setRepeatCount(0);
        icon3Anim_x.setRepeatCount(0);
        icon3Anim.start();
        icon3Anim_x.start();
        ObjectAnimator icon3Anim_scaley=ObjectAnimator.ofFloat(icon3,"scaleY",1,1,0.5f,0);
        icon3Anim_scaley.setDuration(1000);
        icon3Anim_scaley.setRepeatCount(0);
        icon3Anim_scaley.setRepeatMode(ValueAnimator.RESTART);
        icon3Anim_scaley.start();
        ObjectAnimator icon3Anim_scalex=ObjectAnimator.ofFloat(icon3,"scaleX",1,1,0.5f,0);
        icon3Anim_scalex.setDuration(1000);
        icon3Anim_scalex.setRepeatCount(0);
        icon3Anim_scalex.setRepeatMode(ValueAnimator.RESTART);
        icon3Anim_scalex.start();






    }




}

 

按钮点击,弹出三个按钮

标签:ota   import   animator   atm   wrap   ant   app   tar   example   

原文地址:http://www.cnblogs.com/Oldz/p/6883612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!