Android图库视图问题

问题描述

| 大家好,我有点困惑,我一直在尝试使用图库视图小部件创建菜单。我想对其进行一点自定义;我希望放大所选的图像,直到他们选择下一张为止。到目前为止,我已经设法使它放大选定的图像,问题是当您滚动到下一张图像时,它们保持放大状态。 我一直在尝试使用适配器视图创建以前查看过的图像的视图来解决此问题,因此我可以删除动画,但它没有分配任何内容,并且创建的视图保持为空。 如何访问以前查看过的图像,以便删除动画? 为任何帮助加油。
public class main extends ListActivity {

private gallery gallery;
private Animation grow;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestwindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
gallery = (gallery) findViewById(R.id.gallery01);
gallery.setAdapter(new AddImgAdp(this));
gallery.setonItemSelectedListener(new OnItemSelectedListener() { 

  public void  onItemSelected  (AdapterView<?>  parent,View  v,int position,long id) {
      Animation grow = AnimationUtils.loadAnimation(main.this,R.anim.grow);

        View sideView = parent.findViewById(position - 1);
        if (sideView != null){
           ((ImageView)sideView).clearanimation();}

        sideView = parent.findViewById(position + 1);
        if (sideView != null){
           ((ImageView)sideView).clearanimation();}

        v.startAnimation(grow);
        v.setLayoutParams(new gallery.LayoutParams(170,150));
        Toast.makeText(main.this,\"\"+ sideView,Toast.LENGTH_SHORT).show();
    }

@Override
public void onnothingSelected(AdapterView<?> arg0) {
}
});

gallery.setonItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent,View v,long id) {
     }
 });
}

public class AddImgAdp extends BaseAdapter {
int galItemBg;
private Context cont;


private Integer[] Imgid = {
R.drawable.intranet,R.drawable.map,R.drawable.info,R.drawable.call2,R.drawable.youtube,R.drawable.message,R.drawable.facebook 
};

public AddImgAdp(Context c) {
cont = c;
TypedArray typArray = obtainStyledAttributes(R.styleable.galleryTheme);

typArray.recycle();
}

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

public Object getItem(int position) {
return position;
}

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

public View getView(int position,View convertView,ViewGroup parent) {
ImageView imgView = new ImageView(cont);

imgView.setimageResource(Imgid[position]);
imgView.setLayoutParams(new gallery.LayoutParams(110,110));
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
imgView.setBackgroundResource(galItemBg);

return imgView;
}
}

}
    

解决方法

        在onItemSelected中,我将执行以下操作:
public void  onItemSelected  (AdapterView<?>  parent,View  v,int position,long id) {
   if(mPreviousView != null) //remove logic

   mPreviousView = v;

   // Other View stuff ...
}
其中mPreviousView在外部声明为:
private View mPreviousView;
我发现此方法比findViewById加/减逻辑更好用。如果该视图为null,则意味着我们暂时没有以前的视图。