Search code examples
androidxmlgridviewandroid-linearlayoutswiperefreshlayout

GridView about GridView


I need a Gridview above another GridView.

With the help of this: how to set Multiple gridview in same layout in android?

i could set two Gridviews in one Layout. I need them both in a SwipeRefreshLayout!

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:baselineAligned="false">

    <GridView
        android:id="@+id/GridView1"
        android:layout_width="465dp"
        android:layout_height="101dp"
        android:layout_marginBottom="100dp"
        android:layout_weight="1"
        android:numColumns="1"
        android:padding="1dp" />

    <GridView
        android:id="@+id/GridView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:layout_weight="1"
        android:footerDividersEnabled="false"
        android:numColumns="3"
        android:padding="1dp" />

</LinearLayout>


</android.support.v4.widget.SwipeRefreshLayout>

But they are next to each other and I cannot set one of it up to the other. You can see my problem in the picture.

If you know how to put one over the other, so that both fill out everything in width, please help me.

Picture


Solution

  • Change your XML attributes for something like this :

    <android.support.v4.widget.SwipeRefreshLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
        <LinearLayout android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:baselineAligned="false"
            android:orientation="vertical">
    
        <GridView
            android:id="@+id/GridView1"
            android:layout_width="match_parent"
            android:layout_height="101dp"
            android:numColumns="1"
            android:padding="1dp" />
    
        <GridView
            android:id="@+id/GridView2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:footerDividersEnabled="false"
            android:numColumns="3"
            android:padding="1dp" />
    
        </LinearLayout>
    
    </android.support.v4.widget.SwipeRefreshLayout>
    

    If you always need 1 column in first GridView(GridView1), I suggest you to use RecyclerView instead.

    Hope it helps !