Search code examples
androidandroid-gallery

Selected ImageView location change to center on click in Gallery View


I used gallery view in which i place multiple imageview dynamically but on click imageview it comes at center and second question how to start first imageview from left of screen.

I do not want to change the place until user scroll horizontally by finger . Is there any way to achieve this. Please help for this..

private  class ImageAdapter extends BaseAdapter{

     public ImageAdapter() {
        //To set blank at bottom and make visible
        TextView textView = (TextView)findViewById(R.id.textView2);
        textView.setVisibility(View.VISIBLE);

        //To set the visibility visible of gallery
        myGallery.setVisibility(View.VISIBLE);
     }

     public int getCount() {
         return ProductItemArray.Image_URL.length;
     }

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

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

     public View getView(int position, View arg1, ViewGroup arg2) {
         ImageView bottomImageView = new ImageView(context);

         if(Helper.isTablet(context))
             bottomImageView.setLayoutParams(new Gallery.LayoutParams(VirtualMirrorActivity.convertDpToPixel(100, context), VirtualMirrorActivity.convertDpToPixel(100, context)));
         else
             bottomImageView.setLayoutParams(new Gallery.LayoutParams(VirtualMirrorActivity.convertDpToPixel(80, context), VirtualMirrorActivity.convertDpToPixel(80, context)));

         UrlImageViewHelper.setUrlDrawable(bottomImageView, ProductItemArray.Image_URL[position]);
         bottomImageView.setBackgroundResource(R.layout.border);

         return bottomImageView;
     }

}

myGallery.setAdapter(new ImageAdapter());
myGallery.setSelection(1);
myGallery.setOnItemClickListener(new OnItemClickListener()
{
    @Override
    public void onItemClick(AdapterView<?> parent, View view, final int position, long arg3)
    {
        linearLayout.removeView(frameImageView);
        Thread newThread = new Thread(new Runnable() {
            public void run() {
                URL url_1 = null;
                try {
                    isAlreadyExistInWishlist = false;
                    VMProductListPaging.productUrl = ProductItemArray.Image_small_URL[position];
                    VMProductListPaging.productId = ProductItemArray.productId[position];
                    VMProductListPaging.productName = ProductItemArray.product_Name[position];

                    url_1 = new URL(ProductItemArray.Image_small_URL[position]);
                    bmp = BitmapFactory.decodeStream(url_1.openConnection().getInputStream());
                    isExecuted = true;
                    bitmapHandler.sendMessage(bitmapHandler.obtainMessage());
                }
                catch (Exception e) {
                    //Toast.makeText(context,"Sorry!! This link appears to be broken",Toast.LENGTH_LONG).show();
                }
            }
        });
        newThread.start();
    }
});

Layout.xml

<Gallery android:id="@+id/galleryView"  android:layout_width="fill_parent" android:layout_height="wrap_content"  
    android:spacing="5dp" android:layout_below="@+id/sendPhoto" android:layout_marginTop="10dp" android:visibility="gone"/> `enter code here`

Solution

  • This Gallery widget which locks on the left of the view rather than the center.

    https://github.com/TheLevelUp/android-left-locked-gallery