• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help Loading image programmatically in relative layout issue

Marvix

Newbie
Hello,

I'm trying to load images from url via Picasso, the issue that is loading all images above each other, at the end I can see only one image, I tried to use margin, but it is applying the same margin to all.
When I change the parent to liner layout all images are shown.

Java:
for (int i = 0; i < length; i++) {
                                JSONObject picObj = pictures.getJSONObject(i);
                                String pictureName = picObj.getString("name");
                                int pictureId = picObj.getInt("id");

                                ImageView imageView = new ImageView(mContext);
                                imageView.setId(pictureId);

                                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(200, 200);
                                params.setMargins(pictureId,10+pictureId,20,20);
                                imageView.setLayoutParams(params);
                               
                                WebServiceUtils.log(mContext, TAG, "Setting image" + pictureName);
                                Picasso.get().load(imageUrl+pictureName).into(imageView);
                                tImagesLayout.addView(imageView);

                            }

Any idea how to solve it, the end result that I need to display the image as a grid of 3 or 2.

Thanks,
 

I tried that but the cells size is not matching ...

upload_2018-12-9_19-45-51.png



The layout:

Java:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="100"
    android:orientation="vertical"
    tools:context=".CarDetailsFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:background="@color/colorWhite"
        android:layout_height="0dp"
        android:layout_weight="15"
        android:elevation="5dp"
        android:padding="5dp"
        android:orientation="vertical"
        >

        <TextView
            android:id="@+id/car_details_first_entery"
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:text="First Entry: "
            android:textColor="@color/black_overlay" />
        <TextView
            android:id="@+id/car_details_last_entery"
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:text="Last Entry: "
            android:textColor="@color/black_overlay" />
        <TextView
            android:id="@+id/car_details_last_exit"
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:text="Last Exit: "
            android:textColor="@color/black_overlay" />
        <TextView
            android:id="@+id/car_details_status"
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:text="Status: "
            android:textColor="@color/black_overlay" />
    </LinearLayout>


    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="85"
        android:gravity="center"
        android:id="@+id/car_details_grid"
        android:columnCount="3"
        android:useDefaultMargins="true"
        android:stretchMode="columnWidth"
        android:alignmentMode="alignBounds"
        android:verticalSpacing="10dp"
        >
    </GridLayout>

</LinearLayout>
 
Back
Top Bottom