Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 775
Terril Thomas Avatar asked Nov 02 '13 12:11

Terril Thomas


2 Answers

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.

like image 78
Alexis C. Avatar answered Oct 25 '22 00:10

Alexis C.


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);
                }
            }
        });
like image 41
hasan Avatar answered Oct 25 '22 00:10

hasan