A good option to replace the Gallery is a ViewPager, works as a listview or gridview, you have to made your own adapter that extends PagerAdater and a layout item. I already use it with this code i attach below, and it works perfectly. good touch response, i hope this can help you out!!!
LAYOUT
<android.support.v4.view.ViewPager
android:id="@+id/gallery_item"
android:layout_width="fill_parent"
android:layout_height="709dp"
android:layout_below="@+id/relative_headerBar"
>
</android.support.v4.view.ViewPager>
CLASS CODE
private ViewPager gallery;
gallery = (ViewPager) findViewById(R.id.gallery_item);
gallery = (ViewPager) findViewById(R.id.gallery_item);
lista_galeria = new ArrayList<ObjectVerGaleria>();
int i=0;
for(i=0;i<listImages.length;i++)
{
ObjectVerGaleria objV = new ObjectVerGaleria();
objV.setUrlImg(listImages[i]);
lista_galeria.add(objV);
}
gallery.setAdapter(new AdapterVerGaleria(ctx, lista_galeria));
gallery.setOnPageChangeListener(new OnPageChangeListener()
{
public void onPageSelected(int pos)
{
String pathImage = listImages[pos].toString();
currentPosFront = pos;
Log.d("setOnItemSelectedListener>>","path:"+pathImage);
}
public void onPageScrolled(int arg0, float arg1, int arg2)
{
// TODO Auto-generated method stub
}
public void onPageScrollStateChanged(int arg0)
{
// TODO Auto-generated method stub
}
});
ADAPTER
public class AdapterVerGaleria extends PagerAdapter {
private Activity ctx;
private ArrayList<ObjectVerGaleria> dataList;
public AdapterVerGaleria(Activity act, ArrayList<ObjectVerGaleria> lista) {
ctx = act;
dataList = lista;
}
public int getCount() {
return dataList.size();
}
public Object getItem(int pos) {
return pos;
}
@Override
public Object instantiateItem(View collection, int pos)
{
ImageView foto = new ImageView(ctx);
//foto.setLayoutParams(new ViewPager.LayoutParams(Gallery.LayoutParams.FILL_PARENT, Gallery.LayoutParams.FILL_PARENT));
foto.setScaleType(ImageView.ScaleType.FIT_XY);
Utils.fetchDrawableOnThread(Utils.getPath(ctx)+"/"+dataList.get(pos).getUrlImg(), foto, true);
((ViewPager)collection).addView(foto);
return foto;
}
@Override
public void destroyItem(View collection, int position, Object view)
{
((ViewPager)collection).removeView((ImageView)view);
}
public long getItemId(int pos) {
return pos;
}
@Override
public boolean isViewFromObject(View view, Object object)
{
// TODO Auto-generated method stub
return view == ((ImageView)object);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…