Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android自定義控件:老版優酷的三級菜單(效果圖 + Demo)

Android自定義控件:老版優酷的三級菜單(效果圖 + Demo)

編輯:關於Android編程

效果圖:

\


<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+1sbX98u8wrejujwvcD4KPHA+MaGiz8i31s721eK49tCnufujrMbkyrW/ydLUwO294s6qsNHI/by2ssu1pbfWs8lsZXZlbDEsbGV2ZWwyLGxldmVsM6OsbGV2ZWwxysfKvNbVz9TKvrXEoaO147v3bGV2ZWwxuvOjrGxldmVsMrvhs/bP1qO7teO792xldmVsMrrzo6xsZXZlbDO74bP2z9aju2xldmVsMixsZXZlbDOz9s/WuvOjrLXju/dsZXZlbDGjrGxldmVsMrrNbGV2ZWwztry74c/7yqeho8i7uvPP+8qnus2z9s/WztLDx9PDtb3By9K7uPa2r7ut0Ke5+6GjPC9wPgo8cD4yoaK2r7ut0Ke5+9PDtb21xMrHUm90YXRlQW5pbWF0aW9uo6zTydPaztLDx7a8ysfTw82s0ru49tCnufujrMTHw7TO0sPH1rvSqtC00ru49sDgo6yw0dCnufvKtc/Wwcu+zb/J0tTBy6Gj0qrKx8q508NSb3RhdGVBbmltYXRpb261xLuwo6zO0sPHu+Gyu7bPtcS4tNPD0rvQqbT6wuujrNXi0fm/qreitcTQp8LKu+GxyL3Ptc2hozwvcD4KPHA+M6GiUm90YXRlQW5pbWF0aW9utcTQ/deqvfjI67rN0P3XqrP2yKXKx7j2v9OhqqGq0vLOqsv7ysfU2ljW4cuzyrHV67e9z/LQ/deqtcSho7TzvNK/ydLUv7S/tM28o7o8L3A+CjxwPjxpbWcgc3JjPQ=="/uploadfile/Collfiles/20141121/20141121090649165.png" alt="\">

整體思路就是這樣,接下來就是一些操作了:

代碼:

1、MyAnimation類:

public class MyAnimation{
	public static void animationIn(View view){
		animationIn(view,0);
	}
	
	public static void animationOut(View view){
		animationOut(view,0);
	}
	
	public static void animationIn(View view,long delay){
		RotateAnimation animation = new RotateAnimation(180, 360, view.getWidth()/2, view.getHeight());
		animation.setDuration(500);
		animation.setFillAfter(true);
		animation.setStartOffset(delay);
		
		view.startAnimation(animation);
	}
	
	public static void animationOut(View view,long delay){
		RotateAnimation animation = new RotateAnimation(0, 180, view.getWidth()/2, view.getHeight());
		animation.setDuration(500);
		animation.setFillAfter(true);
		animation.setStartOffset(delay);
		
		view.startAnimation(animation);
	}
}

2、MainActivity類:

public class MainActivity extends Activity implements OnClickListener{
	private boolean isLevel2showed,isLevel3showed;
	
	private RelativeLayout level1,level2,level3;
	private ImageButton home,menu;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		isLevel2showed = false;
		isLevel3showed = false;
		initLayout();
		initImageButton();
	}

	public void initLayout() {
		level1 = (RelativeLayout)findViewById(R.id.relate_level1);
		level2 = (RelativeLayout)findViewById(R.id.relate_level2);
		level3 = (RelativeLayout)findViewById(R.id.relate_level3);
		
		level2.setVisibility(View.INVISIBLE);
		level3.setVisibility(View.INVISIBLE);
	}

	public void initImageButton() {
		home = (ImageButton)level1.findViewById(R.id.home);
		menu = (ImageButton)level2.findViewById(R.id.menu);
		
		home.setOnClickListener(this);
		menu.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.home:
			if(!isLevel2showed){
				isLevel2showed = true;
				MyAnimation.animationIn(level2);
			}else if(!isLevel3showed){
				isLevel2showed = false;
				MyAnimation.animationOut(level2);
			}else{
				isLevel2showed = false;
				isLevel3showed = false;
				MyAnimation.animationOut(level3);
				MyAnimation.animationOut(level2,500);
			}
			
			break;
		case R.id.menu:
			if(!isLevel3showed){
				isLevel3showed = true;
				MyAnimation.animationIn(level3);
			}else{
				isLevel3showed = false;
				MyAnimation.animationOut(level3);
			}
			break;
		}
	}
}


源碼下載
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved