`
wen742538485
  • 浏览: 237414 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

android 高仿【优酷】圆盘旋转菜单 的实现

阅读更多
MyAnimation.java
Java代码 
package com.ljp.youku;  
 
import android.view.ViewGroup;  
import android.view.animation.Animation;  
import android.view.animation.RotateAnimation;  
 
public class MyAnimation {  
    // 图标的动画(入动画)  
    public static void startAnimationsIn(ViewGroup viewgroup, int durationMillis) {  
 
        viewgroup.setVisibility(0);  
        for (int i = 0; i < viewgroup.getChildCount(); i++) {  
            viewgroup.getChildAt(i).setVisibility(0);  
            viewgroup.getChildAt(i).setClickable(true);  
            viewgroup.getChildAt(i).setFocusable(true);  
        }  
        Animation animation;  
        animation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF,  
                0.5f, Animation.RELATIVE_TO_SELF, 1.0f);  
        animation.setFillAfter(true);  
        animation.setDuration(durationMillis);  
        viewgroup.startAnimation(animation);  
 
    }  
 
    // 图标的动画(出动画)  
    public static void startAnimationsOut(final ViewGroup viewgroup,  
            int durationMillis, int startOffset) {  
 
        Animation animation;  
        animation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF,  
                0.5f, Animation.RELATIVE_TO_SELF, 1.0f);  
        animation.setFillAfter(true);  
        animation.setDuration(durationMillis);  
        animation.setStartOffset(startOffset);  
        animation.setAnimationListener(new Animation.AnimationListener() {  
            @Override 
            public void onAnimationStart(Animation arg0) {}  
            @Override 
            public void onAnimationRepeat(Animation arg0) {}  
            @Override 
            public void onAnimationEnd(Animation arg0) {  
                viewgroup.setVisibility(8);  
                for (int i = 0; i < viewgroup.getChildCount(); i++) {  
                    viewgroup.getChildAt(i).setVisibility(8);  
                    viewgroup.getChildAt(i).setClickable(false);  
                    viewgroup.getChildAt(i).setFocusable(false);  
                }  
            }  
        });  
        viewgroup.startAnimation(animation);  
    }  
 


package com.ljp.youku;

import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;

public class MyAnimation {
// 图标的动画(入动画)
public static void startAnimationsIn(ViewGroup viewgroup, int durationMillis) {

viewgroup.setVisibility(0);
for (int i = 0; i < viewgroup.getChildCount(); i++) {
viewgroup.getChildAt(i).setVisibility(0);
viewgroup.getChildAt(i).setClickable(true);
viewgroup.getChildAt(i).setFocusable(true);
}
Animation animation;
animation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF,
0.5f, Animation.RELATIVE_TO_SELF, 1.0f);
animation.setFillAfter(true);
animation.setDuration(durationMillis);
viewgroup.startAnimation(animation);

}

// 图标的动画(出动画)
public static void startAnimationsOut(final ViewGroup viewgroup,
int durationMillis, int startOffset) {

Animation animation;
animation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF,
0.5f, Animation.RELATIVE_TO_SELF, 1.0f);
animation.setFillAfter(true);
animation.setDuration(durationMillis);
animation.setStartOffset(startOffset);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {}
@Override
public void onAnimationRepeat(Animation arg0) {}
@Override
public void onAnimationEnd(Animation arg0) {
viewgroup.setVisibility(8);
for (int i = 0; i < viewgroup.getChildCount(); i++) {
viewgroup.getChildAt(i).setVisibility(8);
viewgroup.getChildAt(i).setClickable(false);
viewgroup.getChildAt(i).setFocusable(false);
}
}
});
viewgroup.startAnimation(animation);
}

}

TestYoukuActivity.java
Java代码 
package com.ljp.youku;  
 
import android.app.Activity;  
import android.os.Bundle;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.widget.ImageButton;  
import android.widget.RelativeLayout;  
 
public class TestYoukuActivity extends Activity {  
    /** Called when the activity is first created. */ 
    private boolean areLevel2Showing = true, areLevel3Showing = true;  
    private RelativeLayout relate_level2, relate_level3;  
 
    private ImageButton home, menu;  
 
    @Override 
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
 
        findViews();  
        setListener();  
          
    }  
 
    private void findViews() {  
        relate_level2 = (RelativeLayout) findViewById(R.id.relate_level2);  
        relate_level3 = (RelativeLayout) findViewById(R.id.relate_level3);  
        home = (ImageButton) findViewById(R.id.home);  
        menu = (ImageButton) findViewById(R.id.menu);  
    }  
 
    private void setListener() {  
        // 给大按钮设置点击事件  
        home.setOnClickListener(new OnClickListener() {  
            @Override 
            public void onClick(View v) {  
                if (!areLevel2Showing) {  
                    MyAnimation.startAnimationsIn(relate_level2, 500);  
                } else {  
                    if (areLevel3Showing) {  
                        MyAnimation.startAnimationsOut(relate_level2, 500, 500);  
                        MyAnimation.startAnimationsOut(relate_level3, 500, 0);  
                        areLevel3Showing = !areLevel3Showing;  
                    } else {  
                        MyAnimation.startAnimationsOut(relate_level2, 500, 0);  
                    }  
                }  
                areLevel2Showing = !areLevel2Showing;  
            }  
        });  
        menu.setOnClickListener(new OnClickListener() {  
            @Override 
            public void onClick(View v) {  
                if (!areLevel3Showing) {  
                    MyAnimation.startAnimationsIn(relate_level3, 500);  
                } else {  
                    MyAnimation.startAnimationsOut(relate_level3, 500, 0);  
                }  
                areLevel3Showing = !areLevel3Showing;  
            }  
        });  
    }  
 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics