4

I am working on an application that will get images from SD-Card and will respectively show them in the layout like this

enter image description here

The Issue is:

Lets say the user has 100+ files in the SD-Card, to show them in the layout i need to add first 100+ views and then i would do the styling. Wrong approach

My Question is:

What can be done either progamatically or through XML so that i could define only five basic views and depending upon the number of images in the SD-card, it creates the remaining Layouts and views so that i can access them through horizontal scroll view.

My research includes:

I tried using the Grid view layout but it does not full fill my needs as it has a uniform size for all grids. more over i know how to add a layout programmatically but i do not know how to make it work with my design.

2
  • you can use a gridview or staggered gridview github.com/etsy/AndroidStaggeredGrid Commented Jan 29, 2014 at 11:04
  • you could use a gridlayout inside a horizontalScrollView, load a number or files, and load more when the user scrolls to the end. Commented Jan 29, 2014 at 11:14

2 Answers 2

1

You can make it by changing you xml both side scrollable as-

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="320px" android:layout_height="fill_parent">

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linlay" android:layout_width="320px"
        android:layout_height="fill_parent" android:stretchColumns="1"
        android:background="#000000"/>

</HorizontalScrollView>

Sign up to request clarification or add additional context in comments.

Comments

0

Use this approach :-

1.) Put the path to all images in an arraylist.

2.) create a for loop that will run till size of arraylist.

3.) In this loop, create your imageview using code.

ImageView im = new ImageView(this);

4.) to Show image, in src attribute add the path from arraylist.

You need to use some extra layout params to design according your needs.

2 Comments

i need to define relevance of each image with respect to another.. how will we manage it then?
For that you need to create different arraylists for different attributes , and for n no of imageview call the attribute related to that in x arraylist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.