Terril Thomas
Terril Thomas

Reputation: 1506

Different Column number for each rows in GridView android

I have to create UI using the Gridview. The image are dynamic since it is coming from the webservice .

I can define column number using the xml but the item at the zeroth index has to have one full image and then the rest should be divided into columns .

Any Help is appreciated.

Upvotes: 6

Views: 6104

Answers (4)

Terril Thomas
Terril Thomas

Reputation: 1506

I solved it by using ListView .Added a view to listView Header. Then inside the child for the list view I added two view .In the getView method of the custom adapter I incremented the position by one everytime.

P.S: If you want to implement the above view using endless adapter you will have to find a better solution.

Upvotes: 0

hasan
hasan

Reputation: 24205

Based on Jack K Fouani. Some changes that will save entire image from cropping:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

   <!-- Large Image   -->
    <ImageView
         android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true" />
    <!-- //Large Image -->

    <!-- Small Images -->
    <GridView 
      android:id="@+id/list"
      android:numColumns="auto_fit"
      android:columnWidth="120dip"
      android:gravity="center"
      android:layout_width="fill_parent"
      android:layout_weight="1"
      android:layout_height="0dip" >
   </GridView>
    <!-- Small Images -->

</LinearLayout>

A fast solution, others have a lot of work, try it. you may like it.

GridView gv = findViewById(R.id.list);
        gv.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onScroll(AbsListView arg0, int firstVisibleItem, int arg2, int arg3) {
                // TODO Auto-generated method stub
                ImageView iView = findViewById(R.id.image);
                if (firstVisibleItem == 0)
                {
                    iView.setVisibility(View.VISIBLE);
                }
                else
                {
                    iView.setVisibility(View.Gone);
                }
            }
        });

Upvotes: 1

Noob
Noob

Reputation: 2927

you can use GrideView weight=1 and above of it add ImageView

for example if you want to use GrideView this is full example Layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

   <!-- Large Image   -->
    <ImageView
         android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dip"
        android:layout_gravity="center_horizontal"
        android:scaleType="centerCrop" />
    <!-- //Large Image -->

    <!-- Small Images -->
    <GridView 
      android:id="@+id/list"
      android:numColumns="auto_fit"
      android:columnWidth="120dip"
      android:gravity="center"
      android:layout_width="fill_parent"
      android:layout_weight="1"
      android:layout_height="0dip" >
   </GridView>
    <!-- Small Images -->

</LinearLayout>

this layout will be exactly the same of your request

enter image description here

Upvotes: 0

Alexis C.
Alexis C.

Reputation: 93842

You shoud use a TableLayout. GridView does not support spanning operations.

A layout that arranges its children into rows and columns. A TableLayout consists of a number of TableRow objects, each defining a row (actually, you can have other children, which will be explained below). TableLayout containers do not display border lines for their rows, columns, or cells. Each row has zero or more cells; each cell can hold one View object. The table has as many columns as the row with the most cells. A table can leave cells empty. Cells can span columns, as they can in HTML.

You can see an example here.

Upvotes: 2

Related Questions