0

i have some images, let's say 4 to 10 images.

i want them to draw horizontally and dynamically resize if more image added.

for example in below script, i have 4 images. but the fourth image not drawed (only 3 images visible) :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical"
    android:gravity="center">

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

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ball_1"
            />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ball_1a"
            />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ball_1b"
            />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ball_1c"
            />
    </LinearLayout>
</LinearLayout>

design screenshot :

enter image description here

any idea to solve ?

thanks in advance

questionasker
  • 2,536
  • 12
  • 55
  • 119

1 Answers1

1

You can use horizontal RecyclerView

Here is how to setup:

LinearLayoutManager layoutManager
    = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);

Check this example: Link

Liar
  • 1,235
  • 1
  • 9
  • 19