zoukankan      html  css  js  c++  java
  • 动画隐藏或者显示控件

    效果图

    二、布局main.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:orientation="vertical" >
        <Button 
            android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_alignParentTop="true"
           android:layout_centerInParent="true"
           android:id="@+id/btn"
           android:text="按下显示动画"/>
    
        
      <ImageView 
          android:layout_width="fill_parent"
          android:layout_height="200dp"
          android:layout_alignParentBottom="true"
          android:id="@+id/img"
          android:src="@drawable/bg"/>
    
    </RelativeLayout>

    三、mainactivity

    package com.ct.hide;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.animation.Animation;
    import android.view.animation.ScaleAnimation;
    import android.widget.Button;
    import android.widget.ImageView;
    
    public class MainActivity extends Activity {
        /** Called when the activity is first created. */
        private ImageView img;
        private Button btn;
        private boolean flag = false;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            img = (ImageView)findViewById(R.id.img);
            btn = (Button)findViewById(R.id.btn);
            btn.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    flag = !flag;
                    if(flag){
                        img.setAnimation(new MenuHideShow().hide());
                        img.setVisibility(View.GONE);
                    }else {
                        img.setAnimation(new MenuHideShow().show());
                        img.setVisibility(View.VISIBLE);
                    }
                }
            });
            
        }
        
        public class MenuHideShow{
            Animation showMenu,hideMenu;
            
            public Animation show(){
                showMenu = new ScaleAnimation(0, 1, 0, 1,
                        Animation.RELATIVE_TO_SELF, 0.5f,
                        Animation.RELATIVE_TO_SELF, 0);
                showMenu.setDuration(1000);
                return showMenu;
            }
            
            public Animation hide(){
                hideMenu = new ScaleAnimation(1, 0, 1, 0,
                        Animation.RELATIVE_TO_SELF, 0.5f,
                        Animation.RELATIVE_TO_SELF, 1);
    
                hideMenu.setDuration(1000);
    
                Log.v("menuAnimation", "hide");
    
                return hideMenu;
            }
        }
    }

     (在F:\java\MyHideShow)

  • 相关阅读:
    px, pt, rpx, rem,
    tomcat报错LifecycleException的解决方案
    servlet系列
    tomcat startup.bat双击闪退解决方案。
    代码页
    editplus工具配置
    正则表达式常见字符集
    单片机TM4C123学习(六):看门狗
    stata学习笔记(七):回归分析和稳健性检验
    单片机TM4C123学习(五):UART的使用
  • 原文地址:https://www.cnblogs.com/ct732003684/p/2860870.html
Copyright © 2011-2022 走看看