RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
浅析:Pulltorefresh使用中碰到的问题

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

十余年的庆安网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。网络营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整庆安建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“庆安网站设计”,“庆安网站推广”以来,每个客户项目都认真落实执行。


 

 

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。

 


网页题目:浅析:Pulltorefresh使用中碰到的问题
分享路径:http://sczitong.cn/article/gjiicj.html