5

当我将 StaggeredGridView 放在 ListView 项目中时,它的高度变为零。我试图在这个答案中修改 onMeasure ,但它没有效果。

修改交错网格视图:

public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
                      MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, expandSpec);

    ViewGroup.LayoutParams params = getLayoutParams();
    params.height = getMeasuredHeight();
}

列表项布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <com.playday.app.views.InfiniteGridView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/pics"
        android:layout_marginTop="@dimen/small"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:item_margin="2dp"
        app:column_count="4" />
</FrameLayout>

谁能帮我解决这个问题?

4

0 回答 0