移动动画 移动之后停留在那里

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

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="0dp"
        android:layout_y="460dp" />


   

 

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="271dp"
        android:layout_height="wrap_content"
        android:layout_x="8dp"
        android:layout_y="380dp" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.45"
            android:text="收起" />

 


        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.45"
            android:text="更多" />

    </LinearLayout>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_x="0dp"
    android:layout_y="0dp"
    android:orientation="vertical" android:id="@+id/plxi_plug">
    </LinearLayout>
   
   
   
</AbsoluteLayout>

 

 

 

 

 

 

 

 

 

 

 

 

 

package gt.gt;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;

public class AnimationActivity extends Activity {
 ImageView iv;
 AnimationDrawable ad;
 View view;
 ListView lv;
 private Animation mTranslateAnimation = null;
 MyAdapter myAdapter;

 Button button1,button2;
 
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  try {
   DisplayMetrics dm;
   dm = this.getApplicationContext().getResources()
     .getDisplayMetrics();
   _screenWidth = dm.widthPixels;
   _screenHeight = dm.heightPixels;
  } catch (Exception e) {
  }

  
  
  button1=(Button) findViewById(R.id.button1);
  button2=(Button) findViewById(R.id.button2);
  
  
  button2.setOnClickListener(new Button.OnClickListener(){
   
   @Override
   public void onClick(View arg0) {
     Intent intent = new Intent(AnimationActivity.this,
     com.mini.box.ui.rslist.ResourceListActivity.class);
     startActivity(intent);
   }
   
  });
  
  lv = new ListView(this);

  LinearLayout mailLayout = (LinearLayout)findViewById(R.id.plxi_plug);

  
 
  

  iv = (ImageView) findViewById(R.id.imageView1);
  iv.setBackgroundResource(R.anim.photos);
  ad = (AnimationDrawable) iv.getBackground();

  myAdapter = new MyAdapter(this, R.layout.row);

  lv.setAdapter(myAdapter);

  iv.setOnClickListener(new View.OnClickListener() {

   @Override
   public void onClick(View v) {
   
    if(View.VISIBLE==lv.getVisibility() ){
     scrolldown();                               //移动动画
    }else{
     
     scrollUp();                               //移动动画
    }

    if (ad.isRunning())
     ad.stop();                      
    else
     ad.start();                              

   }
  });
  mailLayout.addView(lv);

 }

 
 
 int _screenHeight = 0;
 int _screenWidth =0;
 
 
 private void scrollUp() {
  

   TranslateAnimation scrollUp = new TranslateAnimation(0, 0, _screenHeight,  _screenHeight- lv.getMeasuredHeight());         
      scrollUp.setDuration(2500);
      scrollUp.setFillEnabled(true);       
      scrollUp.setAnimationListener(
          new AnimationListener() {

              public void onAnimationStart(Animation animation) {
                  lv.setVisibility(View.VISIBLE);
              }

              public void onAnimationRepeat(Animation animation) {}

              public void onAnimationEnd(Animation animation) { 
              
               //这四个点都是相对于左上的
               lv.layout(0, _screenHeight- lv.getMeasuredHeight(), _screenWidth, _screenHeight);
              
              
              }
          }
      );
      lv.startAnimation(scrollUp);

 }
 
 
 
private void scrolldown() {
  

        TranslateAnimation scrollUp = new TranslateAnimation(0,  0, 0,  _screenHeight );         
        scrollUp.setDuration(2500);
        scrollUp.setFillEnabled(true);       
        scrollUp.setAnimationListener(
            new AnimationListener() {

                public void onAnimationStart(Animation animation) {
                 
                }

                public void onAnimationRepeat(Animation animation) {}

                public void onAnimationEnd(Animation animation) {
                 lv.setVisibility(View.GONE);
                }
            }
        );
        lv.startAnimation(scrollUp);
 
 }


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

热爱Coding

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值