Android动画开发——Animation显示隐藏菜单效果
2012-08-07 15:47
579 查看
这里的菜单并不是按机器上的MENU出现在那种菜单,而是基于Android SDK提供的android.view.animation.TranslateAnimation(extends android.view.animation.Animation)类实例后附加到一个Layout上使之产生的有动画出现和隐藏效果的菜单。
Class TranslateAnimation的使用:Animation有两种定义方法,一种是用Java code,一种是用XML,这里只介绍用code来定义.
main.xml
效果:
Class TranslateAnimation的使用:Animation有两种定义方法,一种是用Java code,一种是用XML,这里只介绍用code来定义.
package com.cn.amenu; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.widget.Button; import android.widget.LinearLayout; public class Amenu extends Activity { private Animation mShowAction = null; private Animation mHiddenAction = null; private LinearLayout mMenu = null; private Button mButton = null; private boolean menuShowed; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mMenu = (LinearLayout) this.findViewById(R.id.menu1); mButton = (Button) this.findViewById(R.id.button01); // 动画 mShowAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f); mShowAction.setDuration(500); mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f); mHiddenAction.setDuration(500); menuShowed=false; mMenu.setVisibility(View.GONE); mButton.setOnClickListener(new btn_click()); } class btn_click implements OnClickListener{ @Override public void onClick(View arg0) { if (menuShowed) { menuShowed=false; mMenu.startAnimation(mHiddenAction); mMenu.setVisibility(View.GONE); }else{ menuShowed=true; mMenu.startAnimation(mShowAction); mMenu.setVisibility(View.VISIBLE); } } } }
main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <LinearLayout android:id="@+id/menu1" android:layout_width="fill_parent" android:layout_height="50px" android:layout_alignParentTop="true" android:background="#ffffff"> <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:text="i am a menu" /> <img src="http://dl.iteye.com/upload/attachment/498976/12e90b24-75e4-38bb-84ca-bfb6426c29ae.jpg" mce_src="http://dl.iteye.com/upload/attachment/498976/12e90b24-75e4-38bb-84ca-bfb6426c29ae.jpg" alt=""> </LinearLayout> <Button android:id="@+id/button01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="click to show / hide menu" /> </RelativeLayout>
效果:
相关文章推荐
- Android动画开发——Animation显示隐藏菜单效果
- Android播放器菜单的显示隐藏动画效果
- Android动画开发——Animation动画效果
- Android 开发笔记 动画效果 --Animation
- Android 开发笔记 动画效果 --Animation 动画专题研究 一
- [Android实例] Android 开发笔记 动画效果 --Animation 动画专题研究 一 [复制链接]
- Android 开发第三弹:自定义左右菜单(滑动动画+蒙版效果)
- 点击显示隐藏菜单,动画效果,半透明,支持所有浏览器
- Android UI开发第十二篇——动画效果Animation
- Android 动画1--View控件的显示和隐藏效果
- Android动画开发——Animation动画效果
- Android动画开发——Animation动画效果
- Android动画开发——Animation动画效果
- 【转】Android动画开发——Animation动画效果
- Android动画开发——Animation动画效果
- android控件显示与隐藏的时候的动画效果
- Android动画开发——Animation动画效果
- Android动画开发——Animation动画效果
- Android动画开发—Animation动画效果详解
- Android动画开发——Animation动画效果