Can anyone help me create an android layout like the image below. It has two columns to store images. Each image has the same width.
Thanks so much,
Can anyone help me create an android layout like the image below. It has two columns to store images. Each image has the same width.
Thanks so much,
The easiest way would be to have two list views side by side and connect their onScroll() methods to scroll each other whenever one them is scrolled. (Don't forget to use a flag that you're scrolling programmatically, or you'll get StackOverflowError (kinda ironic, yeah :) due to infinite recursion). You can shift one of them by scrolling by half the images's height.
This is kind of a cheat though. Better way would be to make a custom layout derived from RelativeLayout that can store ids of last and second to last Views added to it. When next one is added, lay it out to be layout_below="@id/second_to_last", then the newly added View becomes last, the previous last - second to last and next time you'll be adding a view under it. (Yeah, i know, not exactly what you'd call a clear description :) but feel free to ask further questions)
look at pinterest like image gallery loader: https://github.com/etsy/AndroidStaggeredGrid
Quick tip - remember about adding "android:adjustViewBounds="true"" in your xml-layout file for images. Without this, images have big margins on top and bottom.
Just tip, maybe you have problems with this. Also remember about scaling functions in Android
You could create a ScrollView that contains two columns (one vertical LinearLayout for each column). To populate it you simply create an ImageView object for each image and add it to the list by calling linearLayout1.addView(myImageView). PLease note that you might run into memory problems if you add a lot of images...
Your layout file would look something like this:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<!-- Left column -->
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="160dp"
android:layout_height="fill_parent"
android:orientation="verical" />
<!-- Right column -->
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="160dp"
android:layout_height="fill_parent"
android:orientation="verical" />
</LinearLayout>
</ScrollView>