Android图库查看问题

时间:2011-06-14 20:00:28

标签: 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, int position, 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;
}
}

}

1 个答案:

答案 0 :(得分:0)

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,则意味着我们还没有以前的视图。