如何在Android中关闭Listview with Animation?

时间:2012-05-07 06:54:06

标签: android android-animation

如何使用动画关闭Listview 像ListView一样,最后一个项目是第一个,第二个是最后一个第二个,依此类推。 就像它来了。我使用以下链接完成了此操作: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/LayoutAnimation2.html 我想要的是相反的顺序。

我有自定义ListView,我写了以下代码。

public class Hella_AdlightActivity extends Activity implements OnItemClickListener {

  private ListView mListView = null;
  private ItemList_BaseAdapter mBaseAdapter = null;
  private Drawable photoId[] = new Drawable[4];

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    photoId[0] = getResources().getDrawable(R.drawable.one_);
    photoId[1] = getResources().getDrawable(R.drawable.two_);
    photoId[2] = getResources().getDrawable(R.drawable.three_);
    photoId[3] = getResources().getDrawable(R.drawable.four_);

    mListView = (ListView)findViewById(R.id.lst_item);
    mListView.setCacheColorHint(0);

    getAnimation();

    mBaseAdapter = new ItemList_BaseAdapter(this);
    mListView.setAdapter(mBaseAdapter);

    mListView.setOnItemClickListener(this);
  }
  private void getAnimation(){
     AnimationSet set = new AnimationSet(true);

     Animation animation = new AlphaAnimation(0.0f, 1.0f);
     animation.setDuration(3000);
     set.addAnimation(animation);

     animation = 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
     );
     animation.setDuration(2000);
     set.addAnimation(animation);

     LayoutAnimationController controller = new LayoutAnimationController(set, 1.0f);

     mListView.setLayoutAnimation(controller);
  }
  private class ItemList_BaseAdapter extends BaseAdapter{

    private LayoutInflater mLayout = null;
    private Context mContext = null;
    public ItemList_BaseAdapter(Context context){
      this.mContext = context;
      this.mLayout = LayoutInflater.from(mContext);
    }

    public int getCount() {
      return photoId.length;
    }

    public Object getItem(int arg0) {
      return null;
    }

    public long getItemId(int position) {
      return 0;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
      if(convertView == null) {
        convertView = mLayout.inflate(R.layout.cust_list, null);
      }

      ImageView imgItem = (ImageView)convertView.findViewById(R.id.img_items);
      imgItem.setBackgroundDrawable(photoId[position]);
      return convertView;
    }
  }
}

我为Listview Load执行此操作,并且每当用户链接任何列表项

时我想关闭列表

0 个答案:

没有答案