Add imageview and break line

Asked

Viewed 369 times

0

I have an image set in my folder assets, but the quantity will always be changing, so I need to add a ImageView via code.

But since I don’t know how much, I don’t know when they’d come out the window. I need to check if the image would stay outside the window and "break a line", and keep putting the ImageView.

  • Why don’t you use a Listview?

  • But as I would add X images to each item in the list, being that X is not an exact number, it will depend on the size of the device’s resolution. X would be the amount of image the device would support horizontally.

  • I think I understand now: you want to put a number x of horizontal images where this number depends on the resolution, the remaining images move to the next line. Right? Then use a Gridview

  • I’ll give a read on gridview I haven’t used it yet, thanks for the help.

1 answer

1

I did it using 3 LinearLayout

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginRight="2dp"
            android:layout_weight="1"
            android:gravity="start"
            android:id="@+id/l1"
            android:layout_alignParentTop="true"></LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            android:layout_weight="1"
            android:gravity="start"
            android:id="@+id/l2"
            android:layout_alignParentTop="true"></LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="2dp"
            android:layout_weight="1"
            android:gravity="start"
            android:id="@+id/l3"
            android:layout_alignParentTop="true"></LinearLayout>
    </LinearLayout>

But then I divided only in 3 the screen of the cell phone , if the mobile is bigger the image gets bigger if the screen is smaller. The way the L1,L2,L3 is it divides the screen into 3 each LinearLayout is the same size as the other. I put the images per line of code

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.