/**
* 重写gridView 让行数自动显示完,自适应高度, listView 可嵌套
*/
public class NoScrollGridView extends GridView {
public NoScrollGridView(Context context) {
super(context);
}
public NoScrollGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NoScrollGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
布局:
<com.gxtag.teamwork.components.NoScrollGridView
android:id="@+id/img_gif_grid_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="60dp"
android:horizontalSpacing="2dp"
android:verticalSpacing="2dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
/>
如果当我们在需要嵌套的时候,通常不能显示自适应的高度,所以这时候我们就得自定义了,通常GridView能用,这也能稍微改成ListView也是可以的。