標籤:it_xiao小巫 android
Android-設定PullToRefresh下拉重新整理樣式
以下是開原始檔控制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>
可以在布局檔案中設定自訂的這些樣式,使用方法如下:
<com.handmark.pulltorefresh.libaray xmlns:ptr="http://schemas.android.com/apk/res-auto" android:id="@+id/lv" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:cacheColorHint="#00000000" android:divider="@drawable/border" android:fadingEdge="none" android:fadingEdgeLength="0dip" android:scrollbars="none" android:scrollingCache="true" ptr:ptrDrawable="@drawable/infzm_logo" />
注意:需要聲明命名空間:xmlns:ptr=http://schemas.android.com/apk/res-auto
使用自訂屬性:ptr:ptrDrawable="@drawable/logo"
其他屬性使用方法類似。
Android-設定PullToRefresh下拉重新整理樣式