开发者

Android gallery view issue

Hi everyone I’m a little confused I’ve been trying to create a menu using the gallery view widget. I want to customise it a little; I want the selected image to be enlarged till they select the next one. So far I have managed to get it to enlarge the selected image, the problem is when you scroll to next image they stay enlarged. I’ve been attempting to fix this problem using the adapter view to create a view of the previously viewed image so I can remove the animation but it’s not assigning anything and the created view stays null.

How can I access the previously viewed images so I can remove the animation?

Cheers for any help.

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 Inte开发者_如何学编程ger[] 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;
}
}

}


in onItemSelected I would do something like:

public void  onItemSelected  (AdapterView<?>  parent, View  v, int position, long id) {
   if(mPreviousView != null) //remove logic

   mPreviousView = v;

   // Other View stuff ...
}

Where mPreviousView is declared outside like:

private View mPreviousView;

I have found this method to work better then findViewById plus/minus logic. If the view is null that means we don't have a previous view just yet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜