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 7851333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:08:56+00:00 2026-06-02T19:08:56+00:00

How would i optimize the galley view as at the moment as it uses

  • 0

How would i optimize the galley view as at the moment as it uses lots of memory which causes it to lag. I dont know what to use to help prevent lag? Anyway i’ll post all my code related to it. (my picture are about 200kb each and are .jpg format) Any help much appreciated.

Gallery activity:

package kevin.erica.box;
import kevin.erica.box.R.string;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;   
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
public class App2Activity extends Activity {
/** Called when the activity is first created. */
Context context = this; 
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gallery);

    final Button ibgb = (Button) findViewById(R.id.backgallery);
    Gallery g = (Gallery) findViewById(R.id.gallery1);
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    MarginLayoutParams mlp = (MarginLayoutParams) g.getLayoutParams();
    mlp.setMargins((int) -(metrics.widthPixels/2), 
                   mlp.topMargin, 
                   mlp.rightMargin, 
                   mlp.bottomMargin);
    g.setAdapter(new ImageAdapter(this));
    ibgb.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent();
            setResult(RESULT_OK, intent);
            finish(); 
        }
        });




    g.setOnItemClickListener(new OnItemClickListener() {



        public void onItemClick(@SuppressWarnings("rawtypes") AdapterView parent, View v, int position, long id) {
            ImageView imageview = (ImageView) findViewById(R.id.ImageView01);
            imageview.setImageResource(mImageIds[position]);




        }

    });
}



public Integer[] mImageIds = {
        R.drawable.alexbox,
        R.drawable.arm,
        R.drawable.mirror,
        R.drawable.penstache,
        R.drawable.penstache1,
        R.drawable.glasses,
        R.drawable.hatface,
        R.drawable.rubber,
        R.drawable.scarfballs,
        R.drawable.drawing,
        R.drawable.eastercardalex,
        R.drawable.extralifenote,
        R.drawable.mug1


};



public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;

public ImageAdapter(Context c) {
    mContext = c;
    TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
    mGalleryItemBackground = a.getResourceId(
            R.styleable.HelloGallery_android_galleryItemBackground, 0);
    a.recycle();
}
public int getCount() {
    return mImageIds.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 i = new ImageView(mContext);
    i.setImageResource(mImageIds[position]);
    i.setLayoutParams(new Gallery.LayoutParams(170, 150));
    i.setScaleType(ImageView.ScaleType.FIT_XY);
    i.setBackgroundResource(mGalleryItemBackground);

    return i;

}
}
}

The.XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >



<Gallery
    android:id="@+id/gallery1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" android:gravity="left"/>





<ImageView
    android:id="@+id/ImageView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/backgallery"
    android:layout_below="@+id/gallery1"
    android:layout_centerHorizontal="true" />

<Button
    android:id="@+id/backgallery"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:text="Back" 
    android:clickable= "true"
    android:onClick="gallerybackbutton"/>

  • 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-06-02T19:08:58+00:00Added an answer on June 2, 2026 at 7:08 pm

    Try to improve the getView() method of your adapter:

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView v;
        if (convertView == null) {
             v = new ImageView(mContext);
        } else {
             v = (ImageView) convertView;
        }
        v.setImageResource(mImageIds[position]);
        v.setLayoutParams(new Gallery.LayoutParams(170, 150));
        v.setScaleType(ImageView.ScaleType.FIT_XY);
        v.setBackgroundResource(mGalleryItemBackground);
        return v;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would really appreciate it if some of you could help optimize my tables,
I would need some help on how to optimize the query. select * from
I would like to optimize my URL showed in web browsers. I know Routing
I would like to optimize my scp deployment which currently copies all files to
I'm developing a Rails 3 app deployed on Heroku which would like to optimize.
Currently I am working on a project that would use genetic algorithms to optimize
I've got some code which i would like to optimize. First, not bad at
I have a SELECT statement which I would like to optimize. The mysql -
I would like to optimize the following code. Currently it runs around 0.085 seconds
I would like to implement an B+ tree in Java and try to optimize

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.