资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

浅析:Pulltorefresh使用中碰到的问题-创新互联

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

创新互联公司专业为企业提供沙市网站建设、沙市做网站、沙市网站设计、沙市网站制作等企业网站建设、网页设计与制作、沙市企业网站模板建站服务,10多年沙市做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

 

XScrollView,通过看下面的代码你会发现该控件在初始化时已经去动态添加了一个子控件,假如你再去放置内容布局肯定会报错,因为android针对ScrollView的默认设置是只允许包含唯一子空间

public class XScrollView extends ScrollViewimplements 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,默认我们的自定义布局是放置嵌套在其中的


 

 
   
 
   
 
   
 

public void setContentView(ViewGroupcontent) {
       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,就是内容布局,接下来就看代码的



 
   
   
 
    
 
       
   
 

代码变动,在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);
}

以上!另外对APP进行全方位的检测,我都会用这个:www.ineice.com。

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前名称:浅析:Pulltorefresh使用中碰到的问题-创新互联
标题来源:http://cdkjz.cn/article/dshpip.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220