第一 在使用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使用中碰到的问题的更多相关文章

  1. cordova + ionic 使用中碰到的一些问题

    cordova + ionic 使用中碰到的一些问题     No Content-Security-Policy meta tag found. Please add one when using ...

  2. tinkphp5使用中碰到的问题 持续更新

    1.使用助手函数(如controller(),model(),validate())进行实例化时只需要引入think\Controller或think\Model或think\Validate即可,无 ...

  3. 谈一谈flex布局使用中碰到的一些问题

    起因 工作以后由于大量使用到了flex布局而碰到了一些尚不清楚的问题,以及一些有意思的特性,在此写篇博客记录一下. flex三个值的含义 众所周知,flex布局所有的属性有两种:一种作用在弹性容器(F ...

  4. IOS block使用中碰到的一个小坑

    1.先上段代码       __block typeof(self) tmpSelf = self; [tableview addLegendHeaderWithRefreshingBlock:^() ...

  5. phpmyadmin使用中碰到的一些问题

    在导入数据库文件的时候出现 #1062 – Duplicate entry '1′ for key ‘PRIMARY' 说明在上一次的导入中没有完全导入,但是主键是自增的,所以要输入主键才能继续,解决 ...

  6. Qt使用中碰到的问题

    1.发现table第一列在切换后变黑,或多了行数. 一般是编译出来的.exe文件所使用的qt的dll不匹配造成的.一定要使用编译时,所使用的那个版本的qt的dll.

  7. pyhton 关于 configparser 配置 模块 实践使用中碰到的坑

    今天做一个ATM的练习,想要用configparser模块,写一个配置文件,存放用户信息. 结果状况连连,叫苦不迭. 我用configparser模块,想要对配置文件,进行读.写.改.查 功能. 其中 ...

  8. JS使用中碰到的一些问题

    settimeout: 1.setTimeout(function () {//这个则会在1秒后进行弹出1 alert(1); }, 1000); 2.setTimeout(alert(1), 100 ...

  9. android studio使用中碰到Failure [INSTALL_FAILED_OLDER_SDK] 问题

    第一次使用Android studio开发.直接新建一个默认项目运行出现:Failure [INSTALL_FAILED_OLDER_SDK] , 网上很多人说修改build.gradle中的mins ...

随机推荐

  1. iOS开发——开发技巧&Git常用命令

    Git常用命令 初始化git init        加—bare实现远程仓库 配置git config user.name iCocos 配置全局git config —global user.na ...

  2. 【C/C++多线程编程之六】pthread相互排斥量

    多线程编程之线程同步相互排斥量       Pthread是 POSIX threads 的简称,是POSIX的线程标准.          Pthread线程同步指多个线程协调地,有序地同步使用共享 ...

  3. android133 360 06 一键锁频,清楚数据

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  4. Jquery的$命名冲突

    在Jquery中,$是JQuery的别名,所有使用$的地方也都可以使用JQuery来替换,如$('#msg')等同于JQuery('#msg')的写法.然而,当我们引入多个js库后,在另外一个js库中 ...

  5. 谈谈MVVM和链式网络请求架构

    前言 前一段时间一直在学习iOS的架构.为什么呢? 公司的架构一直是MVC,当我们正式上线的时候,项目已经有了超十万行代码.主要的VC一般都有2000行代码以上. 关键是,目前版本我们只做了三分之一的 ...

  6. mysql语句在客户端与服务端的基本使用

    //把数据库导出到脚本文件mysqldump -uroot -p1234 --databases abc > d:/a/abc.sql------------------------------ ...

  7. Spring在Web项目中的三种启动加载的配置

    在最近的项目中,使用到了spring相关的很多东西,有点把spring的配置给搞混了,从网上查到的资料以及整理了一下. 在Web项目中,启动spring容器的方式有三种,ContextLoaderLi ...

  8. WebService地址变成计算机名的解决办法

    WCF 4.0 has solved this issue in some instances with a new config option that use Request Headers: & ...

  9. cvThreshold

    看了很多很坑的文章. 呵呵哒.而且基本上都是一个地方转载的,英文翻译我用你单独给一个词条么?就不能负点儿责? cvThreshold(img4, img3, 0, 128, CV_THRESH_OTS ...

  10. httperf ---linux web站点压力测试

    一.工具下载&&安装 软件获取 ftp://ftp.hpl.hp.com/pub/httperf/ 这里使用的是如下的版本 ftp://ftp.hpl.hp.com/pub/httpe ...