解决方法就是重写ListView中的onMeasure方法,相当于说就是自定义一个ListView
/**
* 项目名称:MyApplication
* 创建人:huzy
* 创建时间:2017/3/2 14:41
*/
public class AdapterScrollListView extends ListView {
public AdapterScrollListView(Context context) {
super(context);
}
public AdapterScrollListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AdapterScrollListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
然后布局文件:
<com.beidouapp.et.myapplication.view.AdapterScrollListView
android:id="@+id/list_live"
android:layout_below="@+id/iv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
/>
Activity中即代码方面和原生ListView用法一模一样.
在布局时,你若在listView上还进行了其他布局,那么你在运行后,你会发现,运行时,显示的会是listView的顶端,这里我们只需要:
将你的listView控件的获取焦点权限设置为false即可;
listView.setFocusable(false);