溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

下拉刷新PullToRefresh定制

發(fā)布時間:2020-07-18 09:27:05 來源:網(wǎng)絡(luò) 閱讀:598 作者:Lcg_Android 欄目:開發(fā)技術(shù)

  我們使用PullToRefresh庫的時候,下拉的level-list以及刷新的幀動畫都需要自己定制。如果每次都修改庫非常麻煩,特別是一個項目有幾個地方用到不同的樣式,又不能多次關(guān)聯(lián)同樣的庫。所以我們要自定義屬性,在xml文件中就可以直接設(shè)置參數(shù)。


具體實現(xiàn)步驟:

1.在父類LoadingLayout中找到顯示動畫的ImageView控件,此控件自己定義,原來的控件隱藏。

 mLoadingImage = (ImageView) mInnerLayout.findViewById(R.id.img_loading);

2.在attrs文件中

   <declare-styleable name="PullToRefresh">

        <attr name="ptrRefreshDrawable" format="reference" />

        <attr name="ptrPullDrawable" format="reference" />

        <attr name="ptrTotal" format="integer" />


3.// TODO在子類RotateLoadingLayout

refreshDrawable=attrs.getDrawable(R.styleable.PullToRefresh_ptrRefreshDrawable);

pullDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrPullDrawable);

total = attrs.getInteger(R.styleable.PullToRefresh_ptrTotal, total);


4.// TODO 在onPullImpl方法中

int level = (int) (scaleOfLayout >= 1 ? total : scaleOfLayout * total);

if (pullDrawable == null)

       {

 mLoadingImage.setImageResource(R.drawable.homepage_pull_progresses);

       } else

      {

 mLoadingImage.setImageDrawable(pullDrawable);

       }

LevelListDrawable levelList = (LevelListDrawable) mLoadingImage.getDrawable();

levelList.setLevel(level);

5.// TODO 在refreshingImpl中

if (refreshDrawable == null)

{

mLoadingImage.setImageResource(R.drawable.homepage_loading_progressbar);


} else

{

mLoadingImage.setImageDrawable(refreshDrawable);

}

AnimationDrawable drawable = (AnimationDrawable) 6.mLoadingImage.getDrawable();

drawable.start();

// TODO 在resetImpl方法中

if (pullDrawable == null)

{

mLoadingImage.setImageResource(R.drawable.homepage_pull_progresses);

} else

{

mLoadingImage.setImageDrawable(pullDrawable);


}


7.在自己項目里關(guān)聯(lián)庫后

    <com.handmark.pulltorefresh.library.PullToRefreshListView

        android:id="@+id/pull_refresh_list"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        app:ptrPullDrawable="@drawable/homepage_pull_progresses"

        app:ptrRefreshDrawable="@drawable/homepage_loading_progressbar"

        app:ptrTotal="24" />




備注:參考附件上傳的庫里RotateLoadingLayout類和LoadingLayout類

附件:http://down.51cto.com/data/2366510
向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI