ScollerView 内嵌套 ListView

时间:2014-10-28 17:21:16   收藏:0   阅读:356
package com.bluedragonfly.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View.MeasureSpec;
import android.widget.GridView;
import android.widget.ListView;

public class InnerScrollListView extends ListView{

	 public InnerScrollListView(Context context, AttributeSet attrs) {
	        super(context, attrs);
	    }
	 
	    public InnerScrollListView(Context context) {
	        super(context);
	    }
	 
	    public InnerScrollListView(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);
	}

}

  重写ListView

然后在布局文件中

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:fillViewport="true"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:focusable="true"
           android:focusableInTouchMode="true" >
    
            <InnerScrollListView/>
    
        </LinearLayout>    

  

 android:fillViewport="true"

android:focusable="true"
android:focusableInTouchMode="true"这三个属性是必需的,否者会出现ScollerView会自动往下滑动一段距离
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!