//这是activity ,点击item实现动画方式的展开item内隐藏的布局,但是在滑动listview的时//候会出现一点问题!请大家帮忙看一下 ,,谢谢!!!
package com.example.aaaa;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;public class ExpandAnimationDemo extends Activity {
private View viewDe = null;
CustomListAdapter listAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); ListView list = (ListView) findViewById(R.id.udiniList); listAdapter = new CustomListAdapter(this, R.layout.list_item);
for (int i = 0; i < 20; i++)
listAdapter.add("udini" + i);
list.setAdapter(listAdapter); list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, final View view,
int position, long id) {
if (viewDe == null) {
viewDe = view.findViewById(R.id.toolbar);
} else {
ExpandAnimation expandAni = new ExpandAnimation(viewDe, 100);
viewDe.startAnimation(expandAni);
if (viewDe == view.findViewById(R.id.toolbar)) {
viewDe = null;
return;
}
viewDe = view.findViewById(R.id.toolbar);
} ExpandAnimation expandAni = new ExpandAnimation(viewDe, 100); viewDe.startAnimation(expandAni);
}
});
} class CustomListAdapter extends ArrayAdapter<String> {
private View mLastView; public CustomListAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.list_item,
null);
}
System.out.println(position);
View toolbar = convertView.findViewById(R.id.toolbar);



((TextView) convertView.findViewById(R.id.title))
.setText(getItem(position)); return convertView;
} }
}
//这是动画类package com.example.aaaa;import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.LinearLayout.LayoutParams;/**
 * This animation class is animating the expanding and reducing the size of a
 * view. The animation toggles between the Expand and Reduce, depending on the
 * current state of the view
 * 
 * @author Udinic
 * 
 */
public class ExpandAnimation extends Animation {
private View mAnimatedView;
private LayoutParams mViewLayoutParams;
private int mMarginStart, mMarginEnd;
private boolean mIsVisibleAfter = false;
private boolean mWasEndedAlready = false; /**
 * Initialize the animation
 * 
 * @param view
 *            The layout we want to animate
 * @param duration
 *            The duration of the animation, in ms
 */
public ExpandAnimation(View view, int duration) { setDuration(duration);
mAnimatedView = view;
mViewLayoutParams = (LayoutParams) view.getLayoutParams(); // if the bottom margin is 0,
// then after the animation will end it'll be negative, and invisible.
mIsVisibleAfter = (mViewLayoutParams.bottomMargin == 0); mMarginStart = mViewLayoutParams.bottomMargin;
mMarginEnd = (mMarginStart == 0 ? (0 - view.getHeight()) : 0); view.setVisibility(View.VISIBLE);
} @Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t); if (interpolatedTime < 1.0f) { // Calculating the new bottom margin, and setting it
mViewLayoutParams.bottomMargin = mMarginStart
+ (int) ((mMarginEnd - mMarginStart) * interpolatedTime); // Invalidating the layout, making us seeing the changes we made
mAnimatedView.requestLayout(); // Making sure we didn't run the ending before (it happens!)
} else if (!mWasEndedAlready) {
mViewLayoutParams.bottomMargin = mMarginEnd;
mAnimatedView.requestLayout(); if (mIsVisibleAfter) {
mAnimatedView.setVisibility(View.GONE);
}
mWasEndedAlready = true;
}

}
}
//这是list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:padding="20dip" >
    </TextView>    <!-- *********************** -->
    <!-- *** TOOLBAR LAYOUT **** -->
    <!-- *********************** -->    <LinearLayout
        android:id="@+id/toolbar"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:layout_marginBottom="-50dip"
        android:visibility="gone" >        <Button
            android:id="@+id/doSomething1"
            android:layout_width="wrap_content"
            android:layout_height="50dip"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Harder" >
        </Button>        <Button
            android:id="@+id/doSomething2"
            android:layout_width="wrap_content"
            android:layout_height="50dip"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Better" >
        </Button>        <Button
            android:id="@+id/doSomething3"
            android:layout_width="wrap_content"
            android:layout_height="50dip"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Faster" >
        </Button>        <Button
            android:id="@+id/doSomething4"
            android:layout_width="wrap_content"
            android:layout_height="50dip"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Stronger" >
        </Button>
    </LinearLayout>
</LinearLayout>//这是main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >    <ListView
        android:id="@+id/udiniList"
        android:layout_width="fill_parent"
        android:listSelector="#00000000"
        android:layout_height="fill_parent" >
    </ListView></LinearLayout>