Question

Today I had my first time with Android 4.2, and I noticed how the home screen automatically repositions widgets as you drag them:

I recently worked on a similar code for our project, and I have to admit its performance is much worse. My algorithm is really stupid, and I'm looking for better alternatives. This is the closest one I've found yet, but I haven't tested it yet.

From my understanding, this is related to bin packing, but bin packing algorithms focus on putting rectangles as close to each other as possible, while Android implementation focuses on making as few changes as possible from the initial configuration, and thus is aesthetically pleasing.

Because Android is open source, I hoped to learn from their code, but I can't find anything related to laying out rectangles in android.appwidget. What is the right place to look at?

Was it helpful?

Solution

I'm not 100% sure but it looks like CellLayout.java from Launcher2 is reponsible for this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top