android TranslateAnimation类作动态菜单
来源:互联网 发布:剑灵人族捏脸数据分享 编辑:程序博客网 时间:2024/05/22 12:56
要实现的效果如图:
代码很简单,主要是TranslateAnimation类的
public TranslateAnimation (int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)
Since: API Level 1
Constructor to use when building a TranslateAnimation from code
Parameters
package com.lenovo.wufl.translateanimationmenu;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;import android.widget.TextView;public class TranslateAnimationMenuActivity extends Activity implementsOnClickListener {private TextView mMenu;private Button mButton;private TranslateAnimation mShowAnimation;private TranslateAnimation mHideAnimation;private boolean isShow;/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);initView();initAnimation();}private void initView() {mMenu = (TextView) findViewById(R.id.menu);mButton = (Button) findViewById(R.id.button);mButton.setOnClickListener(this);mMenu.setVisibility(View.GONE);isShow = false;}private void initAnimation() {// 从自已-1倍的位置移到自己原来的位置mShowAnimation = 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);mHideAnimation = 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);mShowAnimation.setDuration(500);mHideAnimation.setDuration(500);}@Overridepublic void onClick(View v) {if (v.getId() == R.id.button) {if (isShow) {isShow = false;mMenu.startAnimation(mHideAnimation);mMenu.setVisibility(View.GONE);} else {isShow = true;mMenu.startAnimation(mShowAnimation);mMenu.setVisibility(View.VISIBLE);}}}}
布局:
<?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:orientation="vertical" > <TextView android:id="@+id/menu" android:layout_width="fill_parent" android:layout_height="68dp" android:background="@android:color/darker_gray" android:gravity="center" android:text="I am a menu" android:textColor="@android:color/background_dark" /> <Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="show/hide menu" /></RelativeLayout>
- android TranslateAnimation类作动态菜单
- android TranslateAnimation类作动态菜单
- Android基于TranslateAnimation的动画动态菜单
- Android基于TranslateAnimation的动画动态菜单
- Android基于TranslateAnimation的动画动态菜单
- Android基于TranslateAnimation的动画动态菜单
- Android基于TranslateAnimation的动画动态菜单
- android TranslateAnimation
- Android 之 TranslateAnimation类:位移动画类
- android TranslateAnimation类:位置变化动画类
- Android 移动动画- TranslateAnimation
- Android 移动动画- TranslateAnimation
- Android动画TranslateAnimation详解
- Android动画之TranslateAnimation
- android TranslateAnimation滑动动画
- TranslateAnimation类是Android系统中的位置变化动画类
- Android动态切换菜单
- android 动态菜单组件
- zoj 2176 Speed Limit
- 360需要的,不是打工者
- logSvr的日志打印函数
- ruby on Rails:动作视图纵览
- 关于伙伴算法
- android TranslateAnimation类作动态菜单
- linux实时任务调度算法分析
- 详解ASP.NET MVC 2中的新ADO.NET实体框架
- Oracle Install
- [我的ICS] - Platform终于开始了
- 源代码解读Cas实现单点登出(single sign out)功能实现原理
- ASP.NET中的AJAX JavaScript实现
- 一个简单的c++/cli中委托与事件的处理模型
- linux修改系统时间详解