Pulltorefresh使用中碰到的问题
第一 在使用XScrollView布局是,无法在该布局.xml文件,放置内容布局控件,假如放置了会报错,
<com.markmao.pulltorefresh.widget.XScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/page_top"
android:fillViewport="true"
android:scrollbars="none" >
</com.markmao.pulltorefresh.widget.XScrollView>
XScrollView,通过看下面的代码你会发现该控件在初始化时已经去动态添加了一个子控件,假如你再去放置内容布局肯定会报错,因为android针对ScrollView的默认设置是只允许包含唯一子空间
public class XScrollView extends ScrollView implements OnScrollListener {
private LinearLayout mLayout;
private LinearLayout mContentLayout;
public XScrollView(Context context) {
super(context);
initWithContext(context);
}
public XScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
initWithContext(context);
}
public XScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initWithContext(context);
}
private void initWithContext(Context context) {
mLayout = (LinearLayout) View.inflate(context, R.layout.vw_xscrollview_layout, null);
mContentLayout = (LinearLayout) mLayout.findViewById(R.id.content_layout);this.addView(mLayout);
}
该控件源主如何让用户可以嵌套使用者自定义的布局了,我们先看看
R.layout.vw_xscrollview_layout 该布局文件的内部,头部与顶部的咱们先不用管,就看中间的,ID值为 content_layout,默认我们的自定义布局是放置嵌套在其中的
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"> <LinearLayout
android:id="@+id/header_layout"
android:layout_gravity="center_horizontal|top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" /> <LinearLayout
android:id="@+id/content_layout"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" /> <LinearLayout
android:id="@+id/footer_layout"
android:layout_gravity="center_horizontal|bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="ttttt"
android:orientation="vertical" /> </LinearLayout>
public void setContentView(ViewGroup content) {
if (mLayout == null)
return;
if (mContentLayout == null)
mContentLayout = (LinearLayout) mLayout.findViewById(R.id.content_layout);
if (mContentLayout.getChildCount() > 0)
mContentLayout.removeAllViews();
mContentLayout.addView(content);
}
public void setView(View content) {
if (mLayout == null)
return;
if (mContentLayout == null)
mContentLayout = (LinearLayout) mLayout.findViewById(R.id.content_layout);
mContentLayout.addView(content);
}
外部引入 ,设置内容的函数有两个,setContentView,setView
View content = LayoutInflater.from(this).inflate(R.layout.vw_scroll_view_content, null);
scrollview.setContentView()content;
针对这样的情况,看个人因素,假如觉得新增一个布局文件无所谓的话也没事,个人的强迫症太厉害,不喜欢这样,感觉不简洁,所以稍微简单的修改了下
下面的布局文件还是用一个使用XScrollView的布局文件,内容布局也放置在该文件中,但是跟XScrollView就不是父子的关系,而是同级的,ID值 xcollview_content,就是内容布局,接下来就看代码的
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/test_parent"
android:layout_width="match_parent"
android:layout_height="match_parent" > <com.markmao.pulltorefresh.widget.XScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/page_top"
android:fillViewport="true"
android:scrollbars="none" >
</com.markmao.pulltorefresh.widget.XScrollView> <LinearLayout
android:id="@+id/xcollview_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/scroll_view"
android:background="@color/transparent"
android:orientation="vertical" > <ListView
android:id="@+id/content_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:scrollbars="none" />
</LinearLayout> </RelativeLayout>
代码变动,在XScrollView中新增函数 ,需要注意的一个空间它只允许有一个父控件,到此步就结束了第一个问题
public void setDView(View content) {
if (mLayout == null)
return;
if (mContentLayout == null)
mContentLayout = (LinearLayout) mLayout.findViewById(R.id.content_layout);
ViewParent parent = this.getParent();
if (parent instanceof RelativeLayout) {
RelativeLayout r_parent = (RelativeLayout) parent;
r_parent.removeView(content);
}
if (parent instanceof LinearLayout) {
LinearLayout l_parent = (LinearLayout) parent;
l_parent.removeView(content);
}
mContentLayout.addView(content);
}

Pulltorefresh使用中碰到的问题的更多相关文章
- cordova + ionic 使用中碰到的一些问题
cordova + ionic 使用中碰到的一些问题 No Content-Security-Policy meta tag found. Please add one when using ...
- tinkphp5使用中碰到的问题 持续更新
1.使用助手函数(如controller(),model(),validate())进行实例化时只需要引入think\Controller或think\Model或think\Validate即可,无 ...
- 谈一谈flex布局使用中碰到的一些问题
起因 工作以后由于大量使用到了flex布局而碰到了一些尚不清楚的问题,以及一些有意思的特性,在此写篇博客记录一下. flex三个值的含义 众所周知,flex布局所有的属性有两种:一种作用在弹性容器(F ...
- IOS block使用中碰到的一个小坑
1.先上段代码 __block typeof(self) tmpSelf = self; [tableview addLegendHeaderWithRefreshingBlock:^() ...
- phpmyadmin使用中碰到的一些问题
在导入数据库文件的时候出现 #1062 – Duplicate entry '1′ for key ‘PRIMARY' 说明在上一次的导入中没有完全导入,但是主键是自增的,所以要输入主键才能继续,解决 ...
- Qt使用中碰到的问题
1.发现table第一列在切换后变黑,或多了行数. 一般是编译出来的.exe文件所使用的qt的dll不匹配造成的.一定要使用编译时,所使用的那个版本的qt的dll.
- pyhton 关于 configparser 配置 模块 实践使用中碰到的坑
今天做一个ATM的练习,想要用configparser模块,写一个配置文件,存放用户信息. 结果状况连连,叫苦不迭. 我用configparser模块,想要对配置文件,进行读.写.改.查 功能. 其中 ...
- JS使用中碰到的一些问题
settimeout: 1.setTimeout(function () {//这个则会在1秒后进行弹出1 alert(1); }, 1000); 2.setTimeout(alert(1), 100 ...
- android studio使用中碰到Failure [INSTALL_FAILED_OLDER_SDK] 问题
第一次使用Android studio开发.直接新建一个默认项目运行出现:Failure [INSTALL_FAILED_OLDER_SDK] , 网上很多人说修改build.gradle中的mins ...
随机推荐
- UIDatePicker 之显示中文 年月日
picker_start=[[UIDatePicker alloc]initWithFrame:CGRectMake(centerView.frame.size.width/-,centerView. ...
- Flash 无法输入中文的修正方法
在某些运行模式或运行时环境中,Flash 有一个 Bug,文本框与键盘的交互模式会无法输入中文(包括日文等带有输入法状态栏的输入模式),只要对 TextField 文本框实例的 FocusEvent. ...
- Ubuntu下安装Nginx,PHP5(及PHP-FPM),MySQL
.简介: Tomcat在高并发环境下处理动态请求时性能很低,而在处理静态页面更加脆弱.虽然Tomcat的最新版本支持epoll,但是通过Nginx来处理静态页面要比通过Tomcat处理在性能方面好很多 ...
- 《Java并发编程实战》第十一章 性能与可伸缩性 读书笔记
造成开销的操作包含: 1. 线程之间的协调(比如:锁.触发信号以及内存同步等) 2. 添加�的上下文切换 3. 线程的创建和销毁 4. 线程的调度 一.对性能的思考 1 性能与可伸缩性 执行速度涉及下 ...
- springMVC整合xStream
一. 简单介绍: xStream能够轻易的将Java对象转换成xml.JSON.本篇博客将使用springMVC整合利用xStream转换xml. 关于xStream使用的博文:http://blog ...
- Templates
Templates Templates are the site's markup, where images and js, css files are located as well as the ...
- Android Sutido 编译速度优化
虽然Android Studio 此时已经更新到了Android Studio 2.1版本,build 版本android-studio-bundle-143.2739321.但是在安装该版本都是根据 ...
- div 块跟随 鼠标点击
js: $(document).ready(function () { $(".company-contact ul li").click(function (ev) { ...
- MATLAB 误差函数erf(x)
误差函数: 1.误差函数定义为: 它的性质如下: 2 互补误差函数定义为: 它具有如下性质: 下表给出了误差函数的部分数值: 0.00 0.00000 0.05 0.05637 0.10 0.11 ...
- Time complexity analysis of algorithms
时间复杂性的计算一般而言,较小的问题所需要的运行时间通常要比较大的问题所需要的时间少.设一个程序P所占用的时间为T,则 T(P)=编译时间+运行时间. 编译时间与实例特征是无关的,且可假设一个编译过的 ...