<?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);
}
}