android ExpandableListView中的child是一个Gridview

android ExpandableListView中的child是一个Gridview,但是GridView只能显示一行,怎么呢设置

阅读 3.3k
1 个回答

我跟你的相反,GridView嵌套ListView


import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

public class ChildListView extends ListView {

    public ChildListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

    public ChildListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public ChildListView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

关键是onMeasure方法,
你可以将ListView改为GridView,其他不变

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题