0

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

Jaxian
  • 1,146
  • 7
  • 14
Kumakitty
  • 43
  • 1
  • 6

1 Answers1

0

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?

Community
  • 1
  • 1
Er. Kaushik Kajavadara
  • 1,657
  • 2
  • 16
  • 37
  • but RecyclerView needs api 21 or higher,right?there are many people using devices run Andriod 4.XX – Kumakitty Jun 21 '16 at 07:28
  • It is available in backward compatible support library. you can check below link https://developer.android.com/topic/libraries/support-library/features.html#v7-appcompat – Er. Kaushik Kajavadara Jun 21 '16 at 08:52