while I scroll between the layout it takes too long to be able to scroll between the gallerie's pictures. Is there any way to reduce this time?

Posted by Mateo on Stack Overflow See other posts from Stack Overflow or by Mateo
Published on 2011-01-09T10:12:22Z Indexed on 2011/01/11 9:54 UTC
Read the original article Hit count: 275

Hello, 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>>();

@Override
public void onCreate(Bundle savedInstancedState) {
    super.onCreate(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,
            RelativeLayout.LayoutParams.FILL_PARENT);

    layout.addView(scroll, scrollLP);

    realLayout.setOrientation(LinearLayout.VERTICAL);
    realLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT));


    scroll.addView(realLayout);



    TakePic.setId(67);
    TakePic.setOnClickListener(this);
    application = (CaWaApplication) getApplication();

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


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



    realLayout.addView(TakePic);
    oldThumbsLoaded = 0;

    int galler = 100;

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


        ThumbailsManager croppedThumbs = new ThumbailsManager(Thumbails,
                oldThumbsLoaded, 
                ThumbailsDays.get(z));
        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,
                ListID));
        gallery.get(z).setOnItemClickListener(this);
        gallery.get(z).setOnItemLongClickListener(this);
        gallery.get(z).setId(galler);
        galler++;

        realLayout.addView(texts.get(z));
        realLayout.addView(gallery.get(z));
    }


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





    setContentView(layout);
}

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;
                ThumbailsDays.add(thumbpathloaded);
                Days.add(Pictures.get(x).day);
                IDs.add(new ArrayList<Long>());
                currentID++;




            }


            StringBuilder tpath = new StringBuilder();
            tpath.append(Pictures.get(x).path.substring(0,
                    Pictures.get(x).path.length() - 4));
            tpath.append("-t.jpg");
            IDs.get(currentID).add(Pictures.get(x).id);
            ThumbailsPath.add(tpath.toString());

            thumbpathloaded++;

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


            }
        }

    }

    for (int y = 0; y < ThumbailsPath.size(); y++) {
        Thumbails.add(BitmapFactory.decodeFile(ThumbailsPath.get(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

Thanks

Mateo

© Stack Overflow or respective owner

Related posts about dynamic

Related posts about android-layout