淺析:Pulltorefresh使用中碰到的問(wèn)題-創(chuàng)新互聯(lián)

第一在使用XScrollView布局是,無(wú)法在該布局.xml文件,放置內(nèi)容布局控件,假如放置了會(huì)報(bào)錯(cuò)

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供沙市網(wǎng)站建設(shè)、沙市做網(wǎng)站、沙市網(wǎng)站設(shè)計(jì)、沙市網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、沙市企業(yè)網(wǎng)站模板建站服務(wù),10多年沙市做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
<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,通過(guò)看下面的代碼你會(huì)發(fā)現(xiàn)該控件在初始化時(shí)已經(jīng)去動(dòng)態(tài)添加了一個(gè)子控件,假如你再去放置內(nèi)容布局肯定會(huì)報(bào)錯(cuò),因?yàn)閍ndroid針對(duì)ScrollView的默認(rèn)設(shè)置是只允許包含唯一子空間

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 該布局文件的內(nèi)部,頭部與頂部的咱們先不用管,就看中間的,ID值為content_layout,默認(rèn)我們的自定義布局是放置嵌套在其中的

<?xml version="1.0"encoding="utf-8"?>
 
<LinearLayoutxmlns: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(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);
}

外部引入 ,設(shè)置內(nèi)容的函數(shù)有兩個(gè),setContentView,setView

View content =LayoutInflater.from(this).inflate(R.layout.vw_scroll_view_content, null);
scrollview.setContentView()content;

下面的布局文件還是用一個(gè)使用XScrollView的布局文件,內(nèi)容布局也放置在該文件中,但是跟XScrollView就不是父子的關(guān)系,而是同級(jí)的,ID值 xcollview_content,就是內(nèi)容布局,接下來(lái)就看代碼的

<?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>

代碼變動(dòng),在XScrollView中新增函數(shù) ,需要注意的一個(gè)空間它只允許有一個(gè)父控件,到此步就結(jié)束了第一個(gè)問(wèn)題

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);
}

以上!另外對(duì)APP進(jìn)行全方位的檢測(cè),我都會(huì)用這個(gè):www.ineice.com。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

標(biāo)題名稱:淺析:Pulltorefresh使用中碰到的問(wèn)題-創(chuàng)新互聯(lián)
標(biāo)題路徑:http://muchs.cn/article8/dshpip.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、企業(yè)建站、網(wǎng)站建設(shè)微信公眾號(hào)、靜態(tài)網(wǎng)站App設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名