欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

仿扇形菜單動(dòng)畫(huà)效果

系統(tǒng) 1621 0
記得在eoe上有人發(fā)過(guò),但代碼質(zhì)量不好。我重寫(xiě)了一下,抽成了控件。但沒(méi)有經(jīng)過(guò)各種控件的相容性測(cè)試,如果和其他控件的相容性不好,就直接在activity中寫(xiě)代碼吧,應(yīng)該差不多的。
我用的是平板,所以效果還行,不知道手機(jī)如何。

仿扇形菜單動(dòng)畫(huà)效果

仿扇形菜單動(dòng)畫(huà)效果
代碼:
    
package com.ql.view;

import android.R.anim;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.ql.app.R;

public class AnimButtons extends RelativeLayout{

	private Context context;
	private int leftMargin=0,bottomMargin=0;
	private final int buttonWidth=58;//圖片寬高
	private final int r=180;//半徑
	private final int maxTimeSpent=200;//最長(zhǎng)動(dòng)畫(huà)耗時(shí)
	private final int minTimeSpent=80;//最短動(dòng)畫(huà)耗時(shí)
	private int intervalTimeSpent;//每相鄰2個(gè)的時(shí)間間隔
	private Button[] btns;
	private Button btn_menu;
	private RelativeLayout.LayoutParams params;
	private boolean isOpen = false;//是否菜單打開(kāi)狀態(tài)
	private float angle;//每個(gè)按鈕之間的夾角
	public AnimButtons(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.context=context;
	}
	public AnimButtons(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		this.context=context;
	}
	
	@Override
	protected void onFinishInflate() {
		// TODO Auto-generated method stub
		super.onFinishInflate();
		View view=LayoutInflater.from(context).inflate(R.layout.anim_buttons, this);
		
		initButtons(view);
		
	}

	private void initButtons(View view){
		// TODO Auto-generated method stub
		//6個(gè)按鈕,具體視情況而定
		btns=new Button[6];
		btns[0] = (Button) view.findViewById(R.id.btn_camera);
		btns[1] = (Button) view.findViewById(R.id.btn_with);
		btns[2] = (Button) view.findViewById(R.id.btn_place);
		btns[3] = (Button) view.findViewById(R.id.btn_music);
		btns[4] = (Button) view.findViewById(R.id.btn_thought);
		btns[5] = (Button) view.findViewById(R.id.btn_sleep);
		btn_menu = (Button) view.findViewById(R.id.btn_menu);
		
		leftMargin=((RelativeLayout.LayoutParams)(btn_menu.getLayoutParams())).leftMargin;
		bottomMargin=((RelativeLayout.LayoutParams)(btn_menu.getLayoutParams())).bottomMargin;
		
		for(int i=0;i<btns.length;i++){
			btns[i].setLayoutParams(btn_menu.getLayoutParams());//初始化的時(shí)候按鈕都重合
			btns[i].setTag(String.valueOf(i));
			btns[i].setOnClickListener(clickListener);
		}
		
		intervalTimeSpent=(maxTimeSpent-minTimeSpent)/btns.length;//20
		angle=(float)Math.PI/(2*(btns.length-1));
	}
	
	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh) {
		// TODO Auto-generated method stub
		super.onSizeChanged(w, h, oldw, oldh);
		final int bottomMargins=this.getMeasuredHeight()-buttonWidth-bottomMargin;
//		Log.i("tag", "bottomMargins====="+bottomMargins);
		btn_menu.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub					
				if(!isOpen){
					isOpen = true;
//					btn_menu.startAnimation(animRotate(-45.0f, 0.5f, 0.45f));
					for(int i=0;i<btns.length;i++){
						float xLenth=(float)(r*Math.sin(i*angle));
						float yLenth=(float)(r*Math.cos(i*angle));
//						Log.i("tag", "xLenth======"+xLenth+",yLenth======"+yLenth);
						btns[i].startAnimation(animTranslate(xLenth, -yLenth, leftMargin+(int)xLenth, bottomMargins - (int)yLenth, btns[i], minTimeSpent+i*intervalTimeSpent));
					}
					
				}
				else{					
					isOpen = false;
//					btn_menu.startAnimation(animRotate(90.0f, 0.5f, 0.45f));
					for(int i=0;i<btns.length;i++){
						float xLenth=(float)(r*Math.sin(i*angle));
						float yLenth=(float)(r*Math.cos(i*angle));
//						Log.i("tag", "xLenth======"+xLenth+",yLenth======"+yLenth);
						btns[i].startAnimation(animTranslate(-xLenth, yLenth, leftMargin, bottomMargins, btns[i], maxTimeSpent-i*intervalTimeSpent));
					}
				}
					
			}
		});
		
	}
	private Animation animScale(float toX, float toY){
		// TODO Auto-generated method stub
		Animation animation = new ScaleAnimation(1.0f, toX, 1.0f, toY, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		animation.setInterpolator(context, anim.accelerate_decelerate_interpolator);
		animation.setDuration(400);
		animation.setFillAfter(false);
		return animation;
		
	}
	
	private Animation animRotate(float toDegrees, float pivotXValue, float pivotYValue){
		// TODO Auto-generated method stub
		final Animation animation = new RotateAnimation(0, toDegrees, Animation.RELATIVE_TO_SELF, pivotXValue, Animation.RELATIVE_TO_SELF, pivotYValue);
		animation.setAnimationListener(new AnimationListener(){
			
			@Override
			public void onAnimationStart(Animation animation){
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation){
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation){
				// TODO Auto-generated method stub
				animation.setFillAfter(true);
			}
		});
		return animation;
	}
	
	
	private Animation animTranslate(float toX, float toY, final int lastX, final int lastY,
			final Button button, long durationMillis){
		// TODO Auto-generated method stub
		Animation animation = new TranslateAnimation(0, toX, 0, toY);				
		animation.setAnimationListener(new AnimationListener(){
						
			@Override
			public void onAnimationStart(Animation animation){
				// TODO Auto-generated method stub
								
			}
						
			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
							
			}
						
			@Override
			public void onAnimationEnd(Animation animation){
				// TODO Auto-generated method stub
				params = new RelativeLayout.LayoutParams(0, 0);
				params.height = buttonWidth;
				params.width = buttonWidth;											
				params.setMargins(lastX, lastY, 0, 0);
				button.setLayoutParams(params);
				button.clearAnimation();
						
			}
		});																								
		animation.setDuration(durationMillis);
		return animation;
	}
	
	View.OnClickListener clickListener=new View.OnClickListener(){

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			int selectedItem=Integer.parseInt((String)v.getTag());
			for(int i=0;i<btns.length;i++){
				if(i==selectedItem){
					btns[i].startAnimation(animScale(2.0f, 2.0f));
				}else{
					btns[i].startAnimation(animScale(0.0f, 0.0f));
				}
			}
			if(onButtonClickListener!=null){
				onButtonClickListener.onButtonClick(v, selectedItem);
			}
		}
		
	};
	
	public boolean isOpen(){
		return isOpen;
	}
	
	private OnButtonClickListener onButtonClickListener;
	public interface OnButtonClickListener{
		void onButtonClick(View v,int id);
	}
	public void setOnButtonClickListener(OnButtonClickListener onButtonClickListener){
		this.onButtonClickListener=onButtonClickListener;
	}
}

  

布局anim_buttons.xml:
    
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
	xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
	android:layout_height="fill_parent" 
	android:background="#FFF"
	>
	<Button android:id="@+id/btn_sleep"
		android:layout_width="wrap_content" 
		android:layout_height="wrap_content"
		android:background="@drawable/composer_sleep"
		android:layout_alignParentLeft="true"
		android:layout_alignParentBottom="true"
		/>

	<Button android:id="@+id/btn_thought"
		android:layout_width="wrap_content" 
		android:layout_height="wrap_content"
		android:background="@drawable/composer_thought"
		android:layout_alignParentLeft="true"
		android:layout_alignParentBottom="true"
		/>

	<Button android:id="@+id/btn_music"
		android:layout_width="wrap_content" 
		android:layout_height="wrap_content"
		android:background="@drawable/composer_music"
		android:layout_alignParentLeft="true"
		android:layout_alignParentBottom="true"
		/>

	<Button android:id="@+id/btn_place"
		android:layout_width="wrap_content" 
		android:layout_height="wrap_content"
		android:background="@drawable/composer_place"
		android:layout_alignParentLeft="true"
		android:layout_alignParentBottom="true"
		/>

	<Button android:id="@+id/btn_with"
		android:layout_width="wrap_content" 
		android:layout_height="wrap_content"
		android:background="@drawable/composer_with"
		android:layout_alignParentLeft="true"
		android:layout_alignParentBottom="true"
		/>

	<Button android:id="@+id/btn_camera"
		android:layout_width="wrap_content" 
		android:layout_height="wrap_content"
		android:background="@drawable/composer_camera"
		android:layout_alignParentLeft="true"
		android:layout_alignParentBottom="true"
		/>

	<Button android:id="@+id/btn_menu"
		android:layout_width="58dip" 
		android:layout_height="58dip"
		android:background="@drawable/friends_delete"
		android:layout_alignParentLeft="true"
		android:layout_alignParentBottom="true"
		android:layout_marginLeft="10dip"
		android:layout_marginBottom="10dip"
	/>
</RelativeLayout>

  


用法:
    
public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        AnimButtons animButtons=(AnimButtons)findViewById(R.id.animButtons);
        animButtons.setOnButtonClickListener(new AnimButtons.OnButtonClickListener() {
			
			@Override
			public void onButtonClick(View v, int id) {
				// TODO Auto-generated method stub
				Log.i("tag", "id============="+id);
			}
		});
        
    }

  

    
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
<!--  layout_width,layout_height最好是fill_parent參數(shù) -->
	<com.ql.view.AnimButtons
	    android:id="@+id/animButtons"
	    android:layout_width="fill_parent"
        android:layout_height="fill_parent"
	    />
</LinearLayout>

  


網(wǎng)上又找到一個(gè)相同效果的。呵呵。
http://www.cnblogs.com/mudoot/archive/2012/01/19/path_composer_menu.html

最后一個(gè):
仿扇形菜單動(dòng)畫(huà)效果

可定制的圓形的浮動(dòng)菜單Android控件:CircularFloatingActionMenu
https://github.com/oguzbilgener/CircularFloatingActionMenu

仿扇形菜單動(dòng)畫(huà)效果


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦?。?!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 国产精品91视频 | 欧美十区 | 国产精品视频免费观看 | 奇米影视在线播放 | 亚洲成人小视频 | 日本阿v视频高清在线 | 亚洲高清中文字幕一区二区三区 | www.热| 九色网址| 狠狠色欧美亚洲狠狠色五 | av不卡免费在线 | 色人阁在线 | 成年网站视频在线观看 | 天天做天天爽 | 久久中文字幕一区二区三区 | 一区二区免费 | 国产福利在线免费 | 精品啪啪 | a级毛片在线免费观看 | 久久香蕉国产精品一区二区三 | 国产精品一区二区三区久久久 | 婷婷开心六月久久综合丁香 | 99精品视频在线观看 | 中文字幕视频在线观看 | 日本一区二区三区高清不卡 | 黄色免费在线观看网址 | 国产精品国产三级国产aⅴ入口 | 国产专区精品 | 91精品国产色综合久久 | 日本污网站 | 欧美中文字幕一区二区 | 一道本视频在线观看 | 男女在线无遮挡毛片免费 | av中文字幕在线 | 国产欧美日韩视频 | 日韩免费视频网站 | 911影院 | 九九黄色 | a级黄色片视频 | 亚洲视频免费在线看 | 香蕉啪|