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 ...
随机推荐
- jquery判断输入文字个数的统计代码
1.js代码部分 <script type="text/javascript"> $(function() { function albumNa ...
- Castle IOC FOR MVC 使用方法
Castle Web.API 使用方法 一.创建 WindsorActivator 继承 IHttpControllerActivator public class WindsorActivator ...
- SCO连接AD / SCOM
SCO安装完成后,下载IP包,打开Deployment Manager注册IP包,并将其部属到Runbook Server SCO IP包下载地址:http://technet.microsoft.c ...
- 一个Solr搜索实例,增删改查+高亮+分页
今天个人coding的模块测试,所以闲暇之余继续研究solr,然后顺带写了一个实例,随便搞的,solr真心不熟,期待认识热爱搜索的朋友,共同进步. 1.配置schema.xml文件[solr\coll ...
- POJ 3692 最大独立集
题意:有G个女生,B个男生,所有的女生都互相认识,所有的男生都互相认识,还有N对男女,他们互相认识. 问从中选出最多的人数,是的他们全部互相认识. 思路:这道题的构图很巧妙,对于他的补图构图,对于所有 ...
- air 中的 LocalStore
<ignore_js_op> 在AIR客户端程序中有时需要将用户的一些信息保存在本地,如果信息没有涉及到隐私那么一般用SharedObject类即可将数据存储在本地.由于SharedObj ...
- iOS 图片加载框架- SDWebImage 解读
在iOS的图片加载框架中,SDWebImage可谓是占据大半壁江山.它支持从网络中下载且缓存图片,并设置图片到对应的UIImageView控件或者UIButton控件.在项目中使用SDWebImage ...
- android客户端从服务器端获取json数据并解析的实现代码
今天总结一下android客户端从服务器端获取json数据的实现代码,需要的朋友可以参考下 首先客户端从服务器端获取json数据 1.利用HttpUrlConnection /** * 从指定的U ...
- Convert Date between LocalDateTime
http://blog.progs.be/542/date-to-java-time Java8 has new date and time classes to “replace” the old ...
- background不能填充margin的问题
CSS2 中有5个主要的背景(background)属性,它们是: background-color: 指定填充背景的颜色.background-image: 引用图片作为背景.background- ...