mientras me desplazo entre el diseño, se tarda demasiado en poder desplazarme entre las imágenes de la galería. ¿Hay alguna forma de reducir este tiempo?

this is my first question here, though I've being reading this forum for quite a while. Most of the answers to my doubts are from here :)

Getting back on topic. I'm developing an Android application. I'm drawing a dynamic layout that are basically Galleries, inside a LinearLayout, inside a ScrollView, inside a RelativeLayout. The ScrollView is a must, because I'm drawing a dynamic amount of galleries that most probably will not fit on the screen.

When I scroll inside the layout, I have to wait 3/4 seconds until the ScrollView "deactivates" to be able to scroll inside the galleries. What I want to do is to reduce this time to a minimum. Preferably I would like to be able to scroll inside the galleries as soon as I lift my finger from the screen, though anything lower than 2 seconds would be great as well.

I've being googling around for a solution but all I could find until now where layout tutorials that didn't tackle this particular issue. I was hoping someone here knows if this is possible and if so to give me some hints on how to do so.

I would prefer not to do my own ScrollView to solve this. But if that is the only way I would appreciate some help because I'm not really sure how would I solve this issue by doing that.

this is my layout:

public class PicturesL extends Activity implements OnClickListener,
    OnItemClickListener, OnItemLongClickListener {

private ArrayList<ImageView> imageView = new ArrayList<ImageView>();

private StringBuilder PicsDate = new StringBuilder();

private CaWaApplication application;
private long ListID;

private ArrayList<Gallery> gallery = new ArrayList<Gallery>();
private ArrayList<Bitmap> Thumbails = new ArrayList<Bitmap>();
private String idioma;

private ArrayList<Long> Days = new ArrayList<Long>();
private long oldDay;
private long oldThumbsLoaded;
private ArrayList<Long> ThumbailsDays = new ArrayList<Long>();
private ArrayList<ArrayList<Long>> IDs = new ArrayList<ArrayList<Long>>();

public void onCreate(Bundle savedInstancedState) {
    RelativeLayout layout = new RelativeLayout(this);
    ScrollView scroll = new ScrollView(this);
    LinearLayout realLayout = new LinearLayout(this);
    ArrayList<TextView> texts = new ArrayList<TextView>();

    Button TakePic = new Button(this);
    idioma = com.mateloft.cawa.prefs.getLang(this);
    if (idioma.equals("en")) {
        TakePic.setText("Take Picture");
    } else if (idioma.equals("es")) {
        TakePic.setText("Sacar Foto");

    RelativeLayout.LayoutParams scrollLP =  new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,

    layout.addView(scroll, scrollLP);

    realLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,


    application = (CaWaApplication) getApplication();

    ListID = getIntent().getExtras().getLong("listid");

    LinearLayout.LayoutParams TakeLP = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 

    oldThumbsLoaded = 0;

    int galler = 100;

    for (int z = 0; z < Days.size(); z++) {

        ThumbailsManager croppedThumbs = new ThumbailsManager(Thumbails,
        oldThumbsLoaded = ThumbailsDays.get(z);

        texts.add(new TextView(this));
        texts.get(z).setText("Day " + Days.get(z).toString());
        gallery.add(new Gallery(this));
        gallery.get(z).setAdapter(new ImageAdapter(this, croppedThumbs.getGallery(), 250, 175, true,


    Log.d("PicturesL", "ListID: " + ListID);


private void getAllThumbailsOfID() {

    ArrayList<ModelPics> Pictures = new ArrayList<ModelPics>();

    ArrayList<String> ThumbailsPath = new ArrayList<String>();

    Pictures = application.dataManager.selectAllPics();
    long thumbpathloaded = 0;
    int currentID = 0;
    for (int x = 0; x < Pictures.size(); x++) {

        if (Pictures.get(x).walkname == ListID) {

            if (Days.size() == 0) { Days.add(Pictures.get(x).day); oldDay = Pictures.get(x).day; 
            IDs.add(new ArrayList<Long>()); currentID = 0; }

            if (oldDay != Pictures.get(x).day) {
                oldDay = Pictures.get(x).day;
                IDs.add(new ArrayList<Long>());


            StringBuilder tpath = new StringBuilder();
                    Pictures.get(x).path.length() - 4));


            if (x == Pictures.size() - 1) {
                Log.d("PicturesL", "El ultimo de los arrays, tamaño: " + Days.size());



    for (int y = 0; y < ThumbailsPath.size(); y++) {



I had a memory leak on another activity when screen orientation changed that was making it slower, now it is working better. The scroller is not locking up. But sometimes, when it stops scrolling, it takes a few seconds (2/3) to disable itself. I just want it to be a little more dynamic, is there any way to override the listener and make it stop scrolling ON_ACTION_UP or something like that?

I don't want to use the listview because I want to have each gallery separated by other views, now I just have text, but I will probably separate them with images with a different size than the galleries.

I'm not really sure if this is possible with a listadapter and a listview, I assumed that a view can only handle only one type of object, so I'm using a scrollview of a layout, if I'm wrong please correct me :)

Also this activity works as a preview or selecting the pictures you want to view in full size and manage their values. So its working only with thumbnails. Each one weights 40 kb. Guessing that is very unlikely that a user gets more than 1000~1500 pictures in this view, i thought that the activity wouldn't use more than 40~50 mb of ram in this case, adding 10 more if I open the fullsized view. So I guessed as well most devices are able to display this view in full size. If it doesn't work on low-end devices my plan was to add an option in the app preferences to let user chop this view according to some database values.

And a last reason is that during most of this activity "life-cycle" (the app has pics that are relevant to the view, when it ends the value that selects which pictures are displayed has to change and no more pictures are added inside this instance of this activity); the view will be unpopulated, so most of the time showing everything wont cost much, just at the end of its cycle

That was more or less what I thought at the time i created this layout. I'm open to any sort of suggestion or opinion, I just created this layout a few days ago and I'm trying to see if it can work right, because it suits my app needs. Though if there is a better way i would love to hear it

PD: I've being toying to see how much it can actually draw. I managed to draw 530 galleries with 600 thumbnails on the same layout, the app is using 42 mb, and I don't have access to more memory to start my full sized view afterwards :( .I tried to do the same with 1000 but it throws OutOfMemory error, bitmap size exceeds vm budget. Is there any way to make more memory availeable on high-end devices? Or should I try to figure out a way not to draw everything at once? Would the listview work for more than one type of object?

Muchas Gracias


preguntado el 09 de enero de 11 a las 10:01

1 Respuestas

Why not make your galleries items of a listview? That way you won't have to inflate all of them immediately and can the advantage of the listview recyling mechanism. Some of the slowness you are seeing might be coming from very heavy memory usage. Galleries aren't exactly light widgets so you might be seeing pauses from heavy GC activity once you stop scrolling. ListView with an adapter would also allow you to lazily bind the Galleries to the list, such that during a fling you aren't doing the expensive binding of the galleries.

Respondido el 09 de enero de 11 a las 13:01

I thought about it. But this way looks really nice. Right now I'm creating thumbnails from each picture and load all of them inside this galleries all on the same layout. Each thumbnail weights around 40 kb; I could reduce a little bit their quality to improve performance I guess. My estimate is that the final user will be getting around 300-1500 thumbnails divided in a maximum of 240 galleries. The other option i thought about was to load a fixed amount of galleries (20-30) and reload the next ones if the user reached the bottom of the view. But I'm hoping to find a way to show everything - Mateo

hmm...can you share any of your code? I'm still doubting that what you are seeing is really the scroller locking up. Also, on memory restricted devices loading all those thumbnails is not going to work very well. Why do you need to show everything immediately? With a listview you'll only inflate and bind the components that are actually visibile or partially visible, the rest are off the screen so it's really just a waste of resources. - jfelectron

I've transform my view to fit into a list, creating my own ListAdapter. But I still have one problem. There are some parts of the list (the beginning, middle and the end) that another view is needed to be added within the list items. The problem is that I couldn't add views dynamically with this method. I could only fill the list by making reference to views already created on xml files. Is there any way to add and inflate views dynamically to the listadapter view? I have already identified which views are the one's that need this, the only problem I'm facing is to add this views. - Mateo

I see a few options here. 1) Set the view visibility to GONE and then swap them to VISIBLE based on whatever condition you'd like or use a ViewStub and inflate them dynamically. In the later case, you'll need a listadapter that supports two view types (your normal row and the ViewStub) 2) Use an expandinglistview if it makes sense for these views that you mention to be children of a group that say expands on user click or some other input. - jfelectron

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.