ScrollView嵌套ListView不置顶显示
2016-02-25 11:30
441 查看
Scrollview里面嵌套了一个Listview,我们一般会自定义ListView,重写onMeasure()方法来解决滑动冲突和显示问题.
但是初始时页面不是置顶显示,而是显示到ListView展示数据的位置.
一般解决方法如下
1.在数据加载完成后将ScrollView控件置顶
关于scrollTo()和scrollBy()方法的相关知识和理解建议参考这篇文章
Android Scroller完全解析,关于Scroller你所需知道的一切
2.在ScrollView的跟布局设置
public class MyListView extends ListView { public MyListView(Context context) { // TODO Auto-generated method stub super(context); } public MyListView(Context context, AttributeSet attrs) { // TODO Auto-generated method stub super(context, attrs); } public MyListView(Context context, AttributeSet attrs, int defStyle) { // TODO Auto-generated method stub super(context, attrs, defStyle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } }
但是初始时页面不是置顶显示,而是显示到ListView展示数据的位置.
一般解决方法如下
1.在数据加载完成后将ScrollView控件置顶
scroll_view.smoothScrollTo(0, 0);
关于scrollTo()和scrollBy()方法的相关知识和理解建议参考这篇文章
Android Scroller完全解析,关于Scroller你所需知道的一切
2.在ScrollView的跟布局设置
android:layout_width="match_parent" android:layout_height="match_parent" android:focusable="true" android:focusableInTouchMode="true"
相关文章推荐
- Centos 6.4 安装elasticsearch+kibana
- iOS获取设备信息与应用信息
- ubuntu安装nodejs+pomelo+webstrom
- iOS 9开发小技巧:LayoutGuide,Storyboard Reference
- how-to-use-ps-kill-and-nice-to-manage-processes-in-linux
- 访问控制
- ASP.NET 总结
- 禁止指定user_agent
- 算法导论第三版第五章思考题
- Android调用地图
- jetty插件开发配置
- jQuery插件实现文字无缝向上滚动效果代码
- jQuery zTree加载树形菜单功能
- nginx代理
- FrameLayout和Fragment处理Android应用UI布局实例
- c3p0连接池和服务器连接池对比
- sleep() 和 wait() 有什么区别?
- iOS block教程
- c/c++内存对齐详解
- android remount system