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 >> 2, 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 >> 2, MeasureSpec.AT_MOST); 
        super.onMeasure(widthMeasureSpec, expandSpec); 
    }
}

用于情况:

多的是,APP各种分类 item 

 

posted @ 2016-02-24 17:47  听着music睡  阅读(4621)  评论(0编辑  收藏  举报