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 ...
随机推荐
- Atom远程连接服务器报错服务器版本和客户端版本不一致
Atom远程连接服务器 报错信息: Server version is different than client version Original error message: Version mi ...
- 统计php源码行
嘿嘿,最近在提交文件,需要知道代码行数,简单记录下,由几种不同的方法进行: 1.直接在 linux 上运行下面语句即可,秒杀: find . -name "*.php" -exec ...
- [C语言(VC)] 打造自己的键盘记录器 (zaroty)
说起键盘记录,想必很多朋友都用过网上流传的一些键盘记录软件吧,但是有没有想过自己写一个呢?也许你会想:会不会很复杂啊?我可以很负责的告诉你,写键盘记录是很简单的.你所需要的仅仅是懂得一些C语言的DLL ...
- C#/Access-数据库获取自动编号的最大值
//conStrSQL你改成你的access,我这里用的SQL2005string conStrSQL = "Data Source=xx.xx.xx.xx;Initial Catalog= ...
- ListView Video
com.baidu.frontia.FrontiaApplication ListView Video <item name="android:windowBackground&quo ...
- EasyUI基础入门之Easyloader(载入器)
在了解完easyui的parser(解析器)之后,接下来就是easyloader(简单载入器)的学习了. 什么是EasyLoader 正如其名字一样easyloader的作用是为了动态的载入组件所需的 ...
- android学习日记19--四大组件之Services(服务)
一个Android应用主要由四个基本组件组成,Android四大基本组件分别是Activity,Content Provider内容提供者,Service服务,BroadcastReceiver广播接 ...
- 在centos上使用yum安装redis及php扩展php-redis
.wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -ivh epel-rele ...
- 【剑指Offer学习】【面试题55:字符流中第一个不反复的字符】
题目:请实现一个函数用来找出字符流中第一个仅仅出现一次的字符. 举例说明 比如,当从字符流中仅仅读出前两个字符"go"时.第一个仅仅出现一次的字符是'g'.当从该字符流中读出前六个 ...
- 学习笔记之SQL Programming DB2
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp If you intend to update a column or ...