简体   繁体   中英

Gridview last row being cut off

My item layout is like below:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
android:paddingBottom="16dp"
android:gravity="center">
<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/iv"
    android:adjustViewBounds="true"
    android:src="@drawable/linianzhenti"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tv"
    android:layout_marginTop="8dp"
    android:text="aaa"
    android:textSize="16sp"/>

And then is my main layout:

<ScrollView 
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/grey"
    android:orientation="vertical">
    ...
    ...
    <com.kumakitty.wenquanedu.MyGridView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:horizontalSpacing="16dp"
        android:id="@+id/gridhome2"
        android:numColumns="2">

    </com.kumakitty.wenquanedu.MyGridView>
</LinearLayout>

Here is MyGridView.class:

public class MyGridView extends GridView {
public MyGridView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public MyGridView(Context context) {
    super(context);
}

public MyGridView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int mExpandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, mExpandSpec);
}
}

Images were diaplayed with ImageLoader I think it may caused by the various heights of images How can I solve it? Any help will be appreciated:) And please excuse my poor English OTL

This is very bad practice to use GridView inside ScrollView. You can use latest views that supports that type of effect you want for nested scrolling.

Refer below link that shows the best practice to do it:

How to use RecyclerView inside NestedScrollView?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM