0

Here is an example :

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

    <TextView
        android:id="@+id/myText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

     <LinearLayout
        android:id="@+id/imageList" 
        android:layout_below="@+id/myText"
        android:layout_height="match_parent"
        android:layout_width="match_parent">

        <!-- Here come ImageViews -->

      </LinearLayout>

</RelativeLayout>

I dynamically add ImageViews to the LinearLayout, but when there are too much images, there's no return to a new line.

  • Is that even possible with a LinearLayout ? (with weight, orientation...)
  • If not, what architecture should I make for this ?

Here is the ImageView I inflate to the LinearLayout :

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/image"
    android:layout_width="60dp"
    android:layout_height="60dp" />
grena
  • 1,011
  • 1
  • 10
  • 25

2 Answers2

0

You are looking for a control named GridView.

Moreover default orientation of LinearLayout is horzontal. You need to set attribute

android:orientation="vertical"
Hardik Trivedi
  • 5,677
  • 5
  • 31
  • 51
  • I changed my LinearLayout to be a GridView and it works ! I made a special adapter for it, the GridView is in a ListView, but this is another subject. Thanks for your help. I followed this tutorial for the GridView : http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/ And here is the fix for the GridView in the ListView : http://stackoverflow.com/questions/4523609/grid-of-images-inside-scrollview/4536955#4536955 – grena Nov 28 '12 at 14:09
0

It's possible. I had already implemented this while I was working in my previous company. Unfortunately, I don't have that demo project with me. I will just give you steps for that.

Step 1: Find width and height of the device which is being used to run an application.

Step 2: Keep tracking the count as how many images are already inserted in layout.

Step 3: Add new row while your device's width = count * (imageview's width) (I was using Table layout so added a new row. You can generate Linearlayout with horizontal orientation in main Linearlayout with vertical orientation)

Hope it helps in implementing