Android项目实战(十五):自定义不可滑动的ListView和GridView

不可滑动的ListView (RecyclweView类似)

public class NoScrollListView extends ListView {
public NoScrollListView(Context context, AttributeSet attrs) {
super(context,attrs);
}
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
int mExpandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> , MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, mExpandSpec);
}
}

用于情况:

社交,社区APP ,例如 QQ空间,一条说说,说说下面的评论用不可滑动的ListView来展示

---------------------------------------------------------------------------------------------------------------------

不可滑动的GridView

public class NonScrollGridView extends GridView {

    public NonScrollGridView(Context context, AttributeSet attrs) {
super(context, attrs);
} public NonScrollGridView(Context context) {
super(context);
} public NonScrollGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
} @Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> , MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}

用于情况:

多的是,APP各种分类 item

上一篇:C# 登陆验证码工具类VerifyCode


下一篇:[agc016B][Colorful Hats]