Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6889647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:10:57+00:00 2026-05-27T06:10:57+00:00

Hello guys i am new to android so be gentle with me :), I

  • 0

Hello guys i am new to android so be gentle with me :),
I have gallery i need to load images i have lot’s of them, the performance on image loading i have solved by using AsyncTask.

Now i have the scrolling on gallery problem, it’s skips images and it’s not looking nice.

Now i have tried to implement my custom Gallery and no success on that, it’s just won’t work

now i have one more question the

final ScrollableGallery galleryView = (ScrollableGallery)findViewById(R.id.gallery); //always returns null

suddenly , can you explane why please?

Here’s the code:

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Gallery;

public class ScrollableGallery extends Gallery {

    public ScrollableGallery(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public ScrollableGallery(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ScrollableGallery(Context context) {
        super(context);
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

        // limit the max speed in either direction
        if (velocityX > 1200.0f) {
            velocityX = 1200.0f;
        } else if (velocityX < 1200.0f) {
            velocityX = -1200.0f;
        }
        return super.onFling(e1, e2, velocityX, velocityY);
    }   
}

The XML part:

<ScrollableGallery
        android:id="@+id/gallery"
        android:layout_width="675dp"
        android:layout_height="492dp"
        android:layout_marginLeft="62dp"
        android:layout_marginTop="225dp"
        android:scaleType="fitXY" >
    </ScrollableGallery>

The Actvity Invocation:
The initiation

final ScrollableGallery galleryView = (ScrollableGallery)findViewById(R.id.gallery);

The adapter initiation:

galleryV.setAdapter(new BaseAdapter() {                     
            public int getCount() {             
                return _imageList.size();
            }

            public Object getItem(int position) {
                return _imageList.get(position);
            }

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

            public View getView(final int position, View convertView,final ViewGroup parent) {              
                if (convertView == null) {
                    convertView = new ImageView(Database.this);
                }               
                ImageDispatcher dispatch = new ImageDispatcher(((ImageView) convertView));              
                dispatch.execute(_imageList.get(position));                                     
                ((ImageView) convertView).setScaleType(ImageView.ScaleType.FIT_XY);
                ((ImageView) convertView).setLayoutParams(new ScrollableGallery.LayoutParams(675, 492));

                return convertView;
            }           
        });
<br/>
The image dispatcher:

    import java.lang.ref.WeakReference;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.os.AsyncTask;
    import android.widget.ImageView;

    public class ImageDispatcher extends AsyncTask<String, Void, Bitmap> {

        private final WeakReference<ImageView> imageViewReference;

        public ImageDispatcher(ImageView imageView) {
            imageViewReference = new WeakReference<ImageView>(imageView);
        }

        @Override
        // Actual download method, run in the task thread
        protected Bitmap doInBackground(String... params) { 

            return ShrinkBitmap(params[0], 300 ,300);
        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            if (isCancelled()) {
                bitmap = null;
            }

            if (imageViewReference != null) {
                ImageView imageView = imageViewReference.get();
                if (imageView != null) {
                    imageView.setImageBitmap(bitmap);
                }
            }
        }

        /*********************************************************
         * PRIVATE METHODS 
         *********************************************************/
        @SuppressWarnings("unused")
        private Bitmap ShrinkBitmap(String file, int width, int height) {
            BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
            bmpFactoryOptions.inTempStorage = new byte[16 * 1024];
            bmpFactoryOptions.inJustDecodeBounds = true;
            Bitmap bitmap = BitmapFactory.decodeFile(file, bmpFactoryOptions);
            int heightRatio = (int) Math.ceil(bmpFactoryOptions.outHeight / (float) height);
            int widthRatio = (int) Math.ceil(bmpFactoryOptions.outWidth / (float) width);

            bmpFactoryOptions.inSampleSize = heightRatio > 1 || widthRatio > 1 ? heightRatio : widthRatio;                  
            bmpFactoryOptions.inJustDecodeBounds = false;
            bitmap = BitmapFactory.decodeFile(file, bmpFactoryOptions);
            return bitmap;
        }

        @SuppressWarnings("unused")
        private Bitmap ShrinkBitmap(String file) {
            BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
            bmpFactoryOptions.inTempStorage = new byte[16 * 1024];
            bmpFactoryOptions.inJustDecodeBounds = true;

            Bitmap bMap = BitmapFactory.decodeFile(file);       
            Bitmap bMapScaled = Bitmap.createScaledBitmap(bMap,150, 100, true);

            return bMapScaled;
        }
    }

I think it’s all the code that i have for this part,
now is the question:
How do i make the scroll, one image in time, and how do i show loading indicator like i do in web when i load images ???

Any code fixing would be highly appreciated !

Thank you in advance…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:10:57+00:00Added an answer on May 27, 2026 at 6:10 am

    Instead of declaring Gallery in you xml.

    Gallery gallery = new  CustomGaller(getActivity());
    
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams  (LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
                params.addRule(RelativeLayout.RIGHT_OF, R.id.left);
                params.addRule(RelativeLayout.LEFT_OF,R.id.right);
                gallery.setLayoutParams(params);
                gallery.setAdapter(new GalleryAdapter(<Pass values>));
    

    You dant have to pass View id to CustomGallery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys I need to make a simple android quiz. Well what I've done
hello guys i have this function for focus : fav[jj].setOnFocusChangeListener(new View.OnFocusChangeListener() { public int
Hello guys sorry if the question looks stupid to you. i have 3 tables
Hello guys, I have been trying to implement the DSUM function but failed to
hello guys i need to sort some elements of integer in an integer array
Hello have only a few days with Java and android here. I am a
Hello guys i have a MSChart and i have some arrows on chart exactly
Hello guys I need to pass a string array over to a setter that
Hello guys, I have a general design problem with iPhone application. I want to
Hello, guys! I'm familiar with JavaScript and PHP, but new to C. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.