码迷,mamicode.com
首页 > 其他好文 > 详细

ScrollView中嵌入ListView,GridView冲突的解决(让ListView全显示出来)

时间:2015-12-18 16:37:45      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

 ScrollView中嵌入原生ListView或GridView,会出现ListView,GridView显示不全的问题。

 解决方法:重新构造一个ListView或GridView,重写OnMeasure()方法:

// ListView

 1 import android.widget.ListView;  
 2   
 3 public class MyListView extends ListView{  
 4   
 5     public MyListView(android.content.Context context,android.util.AttributeSet attrs){  
 6         super(context, attrs);  
 7     }  
 8    
 9     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)  
10     {  
11         int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,  
12                 MeasureSpec.AT_MOST);  
13         super.onMeasure(widthMeasureSpec, expandSpec);  
14   
15     }  
16       
17 } 

 

//GridView

 1 public class MyGridView extends GridView {
 2 
 3     public MyGridView(Context context) {
 4         super(context);
 5         // TODO Auto-generated constructor stub
 6     }
 7 
 8     public MyGridView(Context context, AttributeSet attrs) {
 9         super(context, attrs);
10         // TODO Auto-generated constructor stub
11     }
12     
13     public MyGridView(Context context, AttributeSet attrs, int defStyle) {
14         super(context, attrs, defStyle);
15         // TODO Auto-generated constructor stub
16     }
17     
18     @Override
19     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
20         // TODO Auto-generated method stub
21         
22         int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);
23 
24         super.onMeasure(widthMeasureSpec, expandSpec);
25     }

 

ScrollView中嵌入ListView,GridView冲突的解决(让ListView全显示出来)

标签:

原文地址:http://www.cnblogs.com/xingkai/p/5057294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!