第一 在使用XScrollView布局是,无法在该布局.xml文件,放置内容布局控件,假如放置了会报错,

    <com.markmao.pulltorefresh.widget.XScrollViewandroid: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"><LinearLayoutandroid:id="@+id/header_layout"android:layout_gravity="center_horizontal|top"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical" /><LinearLayoutandroid:id="@+id/content_layout"android:layout_gravity="center"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical" /><LinearLayoutandroid: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.XScrollViewandroid: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><LinearLayoutandroid: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" ><ListViewandroid: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);}

转载于:https://www.cnblogs.com/ak23173969/p/4983088.html

Pulltorefresh使用中碰到的问题相关推荐

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

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

  2. Hadoop Pig 使用中碰到的问题与例子

    在Hive中以默认的格式存储一个外部表(External),从Pig中读取,直接使用PigStorage()即可,rg.apache.pig.piggybank.storage.HiveColumna ...

  3. [转]ExtJs中使用中碰到的三个问题的解决方法

    这里的经验不是指对这种框架总体上面的一些介绍,只是记录了本月中使用ExtJs中遇到的3个问题的解决方法,这里还是要感谢Extjs论坛的 Animal和Condor,每次在我遇到拦路虎的时候,总能在他俩 ...

  4. android底层音频调试,Android音频底层调试-基于tinyalsa,使用中碰到问题

    参考http://blog.csdn.net/zgyrelax/article/details/39397553 已编译出tinyalsa.so, tinymix  tinyplay, tinycap ...

  5. cx_oracle读取数据指定编码,SQLAlchemy和cx_Oracle使用中碰到的数据库编码问题

    1. 系统结构及问题最近在搭建基于Jupyter notebook,panda,dash plotly的数据分析系统.从各个业务系统抽取数据,分析展示. 难免会涉及到中间数据保存,最后返现还是绕不开数 ...

  6. php artisan命令表,php artisan 命令列表

    php  artisan 命令列表 命令获取 上面的翻译内容 命令说明备注 php artisan make:resource ?创建api返回格式化资源>=5.4版本可用 php artisa ...

  7. odbc数据库access丢失_有关使用access数据库,odbc中碰到的一些问题。

    年前写的一个j2ee小项目,数据库用的access,生产环境是在本机,xp,office2003 连接参数如下: driverName=sun.jdbc.odbc.JdbcOdbcDriver url ...

  8. 使用Excel2010条码控件碰到的问题及解决办法

    iamlaosong文 在使用Excel条码过程中碰到几个难以解决的问题,有的问题又因为没有及时发现导致浪费了很多时间和耗材,用户意见也很大.这些问题出现的原因是什么,目前还不知道,所以解决办法也只是 ...

  9. springcloud是什么_阿里P8道出,入职阿里必会199道SpringCloud面试题,你能掌握多少?...

    前言 Spring Cloud 自 2016 年 1 月发布第一个 Angel.SR5 版本,到目前 2020 年 3 月发布 Hoxton.SR3 版本,已经历经了 4 年时间.这 4 年时间里,S ...

最新文章

  1. Handlebars模板引擎
  2. 互联网IP地址的分配
  3. 单片机c语言应用100例第3版课后答案,单片机C语言应用100例(第3版)(含光盘1张)...
  4. [密码学基础][每个信息安全博士生应该知道的52件事][Bristol Cryptography][第14篇]什么是基于线性对的密码学
  5. 计算机信息专业又分为哪三种,计算机类型大致分为哪三类
  6. 我第一次面试自动化测试就被diss了,人生惨遭滑铁卢…
  7. 联想计算机Lenovo ThinkCentre M910t-NO76的重装
  8. 【设计模式专题】Singleton
  9. Qt读写Excel--QXlsx工作表显示/隐藏状态设置4
  10. 安全合规/法案--35--《APP收集使用个人信息自评估指南(征求意见稿)》原文及解读
  11. 非度量多维标度_用R语言做非度量多维尺度分析(NMDS)
  12. 操作系统概论02323-2110期
  13. migo获利能力段增加新字段
  14. 自恢复保险丝在汽车电子中的防护应用
  15. Java学习笔记 (二十七) 使用NIO写文件
  16. 让你对DC完全了解的88条名词解释(转)
  17. ParallaxOcclusionMapping( POM ) DX9
  18. H5(HTML)网页制作基础
  19. Qt之Switch菜单
  20. STM32L0 内部EEPROM写读

热门文章

  1. c语言可视化_这些算法可视化网站助你轻松学算法
  2. 自己动手写cpu pdf_自己动手写 Promise
  3. mysql网页后台_jsp+servlet+mysql开发java web旅游网站,有后台管理系统
  4. c语言作业扩展名通常为什么,C语言的源程序通常的扩展名是( )
  5. oracle存储空间管理,Oracle存储空间管理
  6. logistic回归 如何_第七章:利用Python实现Logistic回归分类模型
  7. 【工具软件】webstorm如何使用快捷键生成固定代码
  8. mpvue 引入自己创建的js 文件 到其他的文件中
  9. vanpopup 高度_解决VantUI popup 弹窗不弹出或无蒙层的问题
  10. iOS SDWebImage加载webp