PullToRefresh Demo 淺析:自定義刷新(refreshview)樣式


PullToRefresh除了可以自己定制刷新的內容之外,最重要的還是在與當用戶下拉和上拉時候的樣式問題。

打開library源碼,發現refreshview的樣式定義在了LoadingLayout類中。

public abstract class LoadingLayout extends FrameLayout implements ILoadingLayout {

構造函數中:

switch (scrollDirection) {
            case HORIZONTAL:
                LayoutInflater.from(context).inflate(R.layout.pull_to_refresh_header_horizontal, this);
                break;
            case VERTICAL:
            default:
                LayoutInflater.from(context).inflate(R.layout.pull_to_refresh_header_vertical, this);
                break;
        }

可以看出根據不同的方向選用不同的布局,所以對於自定義refreshview來說,就是重新選擇布局。

參考:http://www.2cto.com/kf/201501/368016.html


附帶:PullToRefresh的自定義樣式屬性:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="PullToRefresh">
    <!-- A drawable to use as the background of the Refreshable View -->
    <!-- 設置整個刷新列表的背景色 -->
    <attr name="ptrRefreshableViewBackground" format="reference|color" />
    <!-- A drawable to use as the background of the Header and Footer Loading Views -->
    <!--  設置下拉Header或者上拉Footer的背景色 -->
    <attr name="ptrHeaderBackground" format="reference|color" />
    <!-- Text Color of the Header and Footer Loading Views -->
    <!-- 用於設置Header與Footer中文本的顏色 -->
    <attr name="ptrHeaderTextColor" format="reference|color" />
    <!-- Text Color of the Header and Footer Loading Views Sub Header -->
    <!-- 用於設置Header與Footer中上次刷新時間的顏色 -->
    <attr name="ptrHeaderSubTextColor" format="reference|color" />
    <!-- Mode of Pull-to-Refresh that should be used -->
    <attr name="ptrMode">
      <flag name="disabled" value="0x0" /><!-- 禁用下拉刷新 -->
      <flag name="pullFromStart" value="0x1" /><!-- 僅支持下拉刷新 -->
      <flag name="pullFromEnd" value="0x2" /><!-- 僅支持上拉刷新 -->
      <flag name="both" value="0x3" /><!-- 上拉刷新和下拉刷新都支持 -->
      <flag name="manualOnly" value="0x4" /><!-- 只允許手動觸發 -->

      <!-- These last two are depreacted -->
      <flag name="pullDownFromTop" value="0x1" />
      <flag name="pullUpFromBottom" value="0x2" />
    </attr>
    <!-- Whether the Indicator overlay(s) should be used -->
    <!-- 如果為true會在mPullRefreshListView中出現icon,右上角和右下角,挺有意思的 -->
    <attr name="ptrShowIndicator" format="reference|boolean" />
    <!-- Drawable to use as Loading Indicator. Changes both Header and Footer. -->
    <!-- 同時改變頭部和底部的圖標 -->
    <attr name="ptrDrawable" format="reference" />
    <!-- Drawable to use as Loading Indicator in the Header View. Overrides value set in ptrDrawable. -->
    <!-- 頭部視圖的圖標-->
    <attr name="ptrDrawableStart" format="reference" />

    <!-- Drawable to use as Loading Indicator in the Footer View. Overrides value set in ptrDrawable. -->
    <!-- 底部視圖的圖標 -->
    <attr name="ptrDrawableEnd" format="reference" />
    <!-- Whether Android's built-in Over Scroll should be utilised for Pull-to-Refresh. -->
    <attr name="ptrOverScroll" format="reference|boolean" />
    <!-- Base text color, typeface, size, and style for Header and Footer Loading Views -->
     <!-- 分別設置拉Header或者上拉Footer中字體的類型顏色等等 -->
    <attr name="ptrHeaderTextAppearance" format="reference" />
    <!-- Base text color, typeface, size, and style for Header and Footer Loading Views Sub Header -->
    <attr name="ptrSubHeaderTextAppearance" format="reference" />
    <!-- Style of Animation should be used displayed when pulling. -->
    <attr name="ptrAnimationStyle">
      <flag name="rotate" value="0x0" /><!-- flip(翻轉動畫), rotate(旋轉動畫)  -->
      <flag name="flip" value="0x1" />
    </attr>
    <!-- Whether the user can scroll while the View is Refreshing -->
    <!-- 刷新的時候,是否允許ListView或GridView滾動 -->
    <attr name="ptrScrollingWhileRefreshingEnabled" format="reference|boolean" />
    <!--
      Whether PullToRefreshListView has it's extras enabled. This allows the user to be 
      able to scroll while refreshing, and behaves better. It acheives this by adding
      Header and/or Footer Views to the ListView.
    -->
    <!-- 決定了Header,Footer以何種方式加入mPullRefreshListView,true為headView方式加入,就是滾動時刷新頭部會一起滾動 -->
    <attr name="ptrListViewExtrasEnabled" format="reference|boolean" />
    <!--
      Whether the Drawable should be continually rotated as you pull. This only
      takes effect when using the 'Rotate' Animation Style.
    -->
    <attr name="ptrRotateDrawableWhilePulling" format="reference|boolean" />
    <!-- BELOW HERE ARE DEPRECEATED. DO NOT USE. -->
    <attr name="ptrAdapterViewBackground" format="reference|color" />
    <attr name="ptrDrawableTop" format="reference" />
    <attr name="ptrDrawableBottom" format="reference" />
  </declare-styleable>
</resources>

通過在layout文件中定義不同的屬性,基本能夠滿足我們自己做項目的需求。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM