Different column number for each row in android gridview

I need to create an interface using Gridview. The image is dynamic because it comes from a web service.

I can determine the column number using xml, but the element at zero index should have one full image, and then the rest should be divided into columns.

Any help is appreciated.

+4
source share
4 answers

I solved this with a ListView. Added view to ListView Header. Then inside the child element for the list view, I added two views. In the getView method of the custom adapter, each time I increased the position by one.

P.S: , .

0

TableLayout. GridView spanning.

, . TableLayout TableRow, ( , ). TableLayout , . ; View. , . . , HTML.

.

+2

. , :

<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>

, - , . .

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);
                }
            }
        });
+1

you can use GrideViewweight = 1 and above add itImageView

for example, if you want to use GrideView, this is a complete Layout example

<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 as your request

enter image description here

0
source

All Articles