Android利用属性动画实现优酷菜单

利用属性动画实现优酷菜单,供大家参考,具体内容如下

布局文件





 

 

 

 

 

 


 




 

 

 




 


核心代码

package com.example.uumusic.menu;

import android.content.Context;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.example.uumusic.R;
import com.example.uumusic.fragment.base.BasePager;
import com.example.uumusic.utils.Tools;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Administrator on 2017.06.07.0007.
 */

public class YoukuMenu extends BasePager {

@InjectView(R.id.c1)
ImageButton c1;
@InjectView(R.id.c2)
ImageButton c2;
@InjectView(R.id.c3)
ImageButton c3;
@InjectView(R.id.c4)
ImageButton c4;
@InjectView(R.id.c5)
ImageButton c5;
@InjectView(R.id.c6)
ImageButton c6;
@InjectView(R.id.c7)
ImageButton c7;
@InjectView(R.id.level3)
RelativeLayout level3;
@InjectView(R.id.search)
ImageButton search;
@InjectView(R.id.menu)
ImageButton menu;
@InjectView(R.id.myyouku)
ImageButton myyouku;
@InjectView(R.id.level2)
RelativeLayout level2;
@InjectView(R.id.home)
ImageButton home;
private boolean isLeve12 = true;
private boolean isLeve13 = true;

public YoukuMenu(Context context) {
 super(context);
}

@Override
public View initView() {
 View view = View.inflate(mContext, R.layout.fragment_youku, null);
 ButterKnife.inject(this,view);
 return view;
}

@Override
public void initData() {
 //为按钮设置点击事件
 home.setOnClickListener(new MyOnClickLisetner());
 menu.setOnClickListener(new MyOnClickLisetner());

}

class MyOnClickLisetner implements View.OnClickListener{

 @Override
 public void onClick(View v) {
 switch (v.getId()){
  case R.id.home:
  //当点击home按钮时,开始进行动画的效果
  if (isLeve12){
   isLeve12 = false;
   Tools.hide(level2);
   if (isLeve13){
   isLeve13 = false;
   Tools.hide(level3,200);
   }
  }else {
   isLeve12 = true;
   Tools.show(level2);
  }
  break;
  case R.id.menu:

  if (isLeve13){
   isLeve13 = false;
   Tools.hide(level3);
  }else {
   isLeve13 = true;
   Tools.show(level3);
  }
  break;
 }
 }
}
}

动画工具类

package com.example.uumusic.utils;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.RotateAnimation;
import android.widget.RelativeLayout;

/**
 * Created by Administrator on 2017.06.07.0007.
 */
public class Tools {

//隐藏布局
public static void hide(ViewGroup view) {
 hide(view, 0);
}

//显示布局
public static void show(ViewGroup view) {

 //使用属性动画实现菜单的旋转
 ObjectAnimator animator = ObjectAnimator.ofFloat(view,"rotation",180,360);
 //设置动画时长
 animator.setDuration(300);
 animator.start();
 view.setPivotX(view.getWidth()/2);
 view.setPivotY(view.getHeight());
}

//延迟隐藏
public static void hide(ViewGroup view, int i) {
 ObjectAnimator animator = ObjectAnimator.ofFloat(view,"rotation",0,180);
 //设置动画时长
 animator.setDuration(300);
 //设置延迟
 animator.setStartDelay(i);
 animator.start();
 view.setPivotX(view.getWidth()/2);
 view.setPivotY(view.getHeight());
}
}

源码:Android利用属性动画实现优酷菜单

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

你可能感兴趣的:(Android利用属性动画实现优酷菜单)