AndroidStaggeredGrid icon indicating copy to clipboard operation
AndroidStaggeredGrid copied to clipboard

Wrong size when StaggeredGridView placed inside weighted layout

Open TealOcean opened this issue 10 years ago • 5 comments

When i placed a StaggeredGridView inside a weighted layout like so:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:weightSum="5"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/spacer_left"
        android:layout_weight="1"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="16dp"
        android:layout_gravity="bottom"
        android:layout_width="0dp"
        android:layout_height="wrap_content">

        <com.nfl.now.ui.TypefaceTextView
            style="@style/NFLNow.TextView.Light"
            android:id="@+id/sponsor_text"
            android:textSize="8sp"
            android:text="@string/sponsor_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            tools:ignore="SmallSp"/>

        <ImageView
            android:layout_below="@id/sponsor_text"
            android:layout_marginTop="2dp"
            android:src="@drawable/sponsor_logo"
            android:layout_width="100dp"
            android:layout_height="wrap_content" />

    </RelativeLayout>

    <GridView
            android:id="@+id/favorite_players"
            android:numColumns="5"
            android:layout_below="@id/header"
            android:layout_above="@id/footer"
            android:layout_weight="3"
            android:layout_width="0dp"
            android:layout_height="wrap_content" />

    <Space
        android:id="@+id/spacer_right"
        android:layout_weight="1"
        android:layout_marginLeft="16dp"
        android:layout_width="0dp"
        android:layout_height="wrap_content" />

</LinearLayout>

The grid only shows 1 column despite the setting for 5. Upon further inspection, all 5 columns are being laid out, but they are being laid out on top of each other!

Could we get a fix? =)

TealOcean avatar May 12 '14 16:05 TealOcean

I have the same problem, any fix for it?

booker0108 avatar Aug 08 '14 04:08 booker0108

I also seem to have the same issue. Any workarounds?

I've attached a dump of the current view hierarchy and a screenshot, for reference. If anyone has any suggestions, let me know. view_hierarchy screenshot

andreimarinescu avatar Oct 17 '14 09:10 andreimarinescu

I meet the same problem, is what the solution?

husongzhen avatar Dec 03 '14 04:12 husongzhen

I meet the same problem, is what the solution?

freecsdn avatar Dec 16 '14 07:12 freecsdn

The solution for us was to call setColumnCount on the UI thread of the activity

andreimarinescu avatar Dec 16 '14 08:12 andreimarinescu