1. 程式人生 > >修改pulltorefresh 下拉重新整理個上拉載入的顯示

修改pulltorefresh 下拉重新整理個上拉載入的顯示

1,在anim目錄下建立動畫

2,生產自己的頭佈局

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
    <FrameLayout
        android:id="@+id/mypull_simple"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="@dimen/header_footer_top_bottom_padding"
        android:paddingLeft="@dimen/header_footer_left_right_padding"
        android:paddingRight="@dimen/header_footer_left_right_padding"
        android:paddingTop="@dimen/header_footer_top_bottom_padding" >
        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" >
            <ImageView
                android:id="@+id/iv_my"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/mystart" >
            </ImageView>
        </FrameLayout>
    </FrameLayout>
</merge>

3,在internal目錄下,設定自己的頭佈局動畫操控佈局

 MyLoadingLayOut

package com.handmark.pulltorefresh.library.internal;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Orientation;
import com.handmark.pulltorefresh.library.R;
public class MyLoadingLayOut extends LoadingLayout {
private Animation loadAnimation;
public MyLoadingLayOut(Context context, Mode mode,Orientation scrollDirection, TypedArray attrs) {
    super(context, mode, scrollDirection, attrs);
    mHeaderImage.setImageResource(R.drawable.mystart);
    loadAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.myrotate);
}
@Override
protected int getDefaultDrawableResId() {
    // TODO Auto-generated method stub
    return R.drawable.mystart;
}
@Override
protected void onLoadingDrawableSet(Drawable imageDrawable) {
    // TODO Auto-generated method stub
}
@Override
protected void onPullImpl(float scaleOfLayout) {
    // TODO Auto-generated method stub
}
//下來重新整理
@Override
protected void pullToRefreshImpl() {
    mHeaderImage.setVisibility(View.VISIBLE);
}
//正在重新整理回撥
@Override
protected void refreshingImpl() {
    mHeaderImage.setVisibility(View.VISIBLE);
    mHeaderImage.startAnimation(loadAnimation);
}
//釋放重新整理
@Override
protected void releaseToRefreshImpl() {
    mHeaderImage.startAnimation(loadAnimation);
}
//重新設定
@Override
protected void resetImpl() {
    mHeaderImage.clearAnimation();
    /*mHeaderProgress.setVisibility(View.GONE);*/
    mHeaderImage.setVisibility(View.VISIBLE);
}
}

4,修改雞肋LoadingLayout

public abstract class LoadingLayout extends FrameLayout implements ILoadingLayout {
static final String LOG_TAG = "PullToRefresh-LoadingLayout";
static final Interpolator ANIMATION_INTERPOLATOR = new LinearInterpolator();
private FrameLayout mInnerLayout;
protected final ImageView mHeaderImage;
/*  protected final ProgressBar mHeaderProgress;*/
private boolean mUseIntrinsicAnimation;
/*private final TextView mHeaderText;
private final TextView mSubHeaderText;*/
protected final Mode mMode;
protected final Orientation mScrollDirection;
private CharSequence mPullLabel;
private CharSequence mRefreshingLabel;
private CharSequence mReleaseLabel;
public LoadingLayout(Context context, final Mode mode, final Orientation scrollDirection, TypedArray attrs) {
    super(context);
    mMode = mode;
    mScrollDirection = scrollDirection;
    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);*/
            LayoutInflater.from(context).inflate(R.layout.pull_to_refresh_header_simple, this);
            break;
    }
   //我自己修改的地方
    mInnerLayout = (FrameLayout) findViewById(R.id.mypull_simple);
/*  mHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_text);
    mHeaderProgress = (ProgressBar) mInnerLayout.findViewById(R.id.pull_to_refresh_progress);
    mSubHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_sub_text);*/
    mHeaderImage = (ImageView) mInnerLayout.findViewById(R.id.iv_my);
    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInnerLayout.getLayoutParams();
    switch (mode) {
        case PULL_FROM_END:
            lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.TOP : Gravity.LEFT;
            // Load in labels
            mPullLabel = context.getString(R.string.pull_to_refresh_from_bottom_pull_label);
            mRefreshingLabel = context.getString(R.string.pull_to_refresh_from_bottom_refreshing_label);
            mReleaseLabel = context.getString(R.string.pull_to_refresh_from_bottom_release_label);
            break;
        case PULL_FROM_START:
        default:
            lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.BOTTOM : Gravity.RIGHT;
            // Load in labels
            mPullLabel = context.getString(R.string.pull_to_refresh_pull_label);
            mRefreshingLabel = context.getString(R.string.pull_to_refresh_refreshing_label);
            mReleaseLabel = context.getString(R.string.pull_to_refresh_release_label);
            break;
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderBackground)) {
        Drawable background = attrs.getDrawable(R.styleable.PullToRefresh_ptrHeaderBackground);
        if (null != background) {
            ViewCompat.setBackground(this, background);
        }
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance)) {
        TypedValue styleID = new TypedValue();
        attrs.getValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance, styleID);
        setTextAppearance(styleID.data);
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance)) {
        TypedValue styleID = new TypedValue();
        attrs.getValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID);
        setSubTextAppearance(styleID.data);
    }
    // Text Color attrs need to be set after TextAppearance attrs
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextColor)) {
        ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderTextColor);
        if (null != colors) {
            setTextColor(colors);
        }
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderSubTextColor)) {
        ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderSubTextColor);
        if (null != colors) {
            setSubTextColor(colors);
        }
    }
    // Try and get defined drawable from Attrs
    Drawable imageDrawable = null;
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawable)) {
        imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawable);
    }
    // Check Specific Drawable from Attrs, these overrite the generic
    // drawable attr above
    switch (mode) {
        case PULL_FROM_START:
        default:
            if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableStart)) {
                imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableStart);
            } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableTop)) {
                Utils.warnDeprecation("ptrDrawableTop", "ptrDrawableStart");
                imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableTop);
            }
            break;
        case PULL_FROM_END:
            if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableEnd)) {
                imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableEnd);
            } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableBottom)) {
                Utils.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd");
                imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableBottom);
            }
            break;
    }
    // If we don't have a user defined drawable, load the default
    if (null == imageDrawable) {
        imageDrawable = context.getResources().getDrawable(getDefaultDrawableResId());
    }
    // Set Drawable, and save width/height
    setLoadingDrawable(imageDrawable);
    reset();
}
public final void setHeight(int height) {
    ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) getLayoutParams();
    lp.height = height;
    requestLayout();
}
public final void setWidth(int width) {
    ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) getLayoutParams();
    lp.width = width;
    requestLayout();
}
public final int getContentSize() {
    switch (mScrollDirection) {
        case HORIZONTAL:
            return mInnerLayout.getWidth();
        case VERTICAL:
        default:
            return mInnerLayout.getHeight();
    }
}
public final void hideAllViews() {
/*  if (View.VISIBLE == mHeaderText.getVisibility()) {
        mHeaderText.setVisibility(View.INVISIBLE);
    }
    if (View.VISIBLE == mHeaderProgress.getVisibility()) {
        mHeaderProgress.setVisibility(View.INVISIBLE);
    }*/
    if (View.VISIBLE == mHeaderImage.getVisibility()) {
        mHeaderImage.setVisibility(View.INVISIBLE);
    }
/*  if (View.VISIBLE == mSubHeaderText.getVisibility()) {
        mSubHeaderText.setVisibility(View.INVISIBLE);
    }*/
}
public final void onPull(float scaleOfLayout) {
    if (!mUseIntrinsicAnimation) {
        onPullImpl(scaleOfLayout);
    }
}
public final void pullToRefresh() {
    /*if (null != mHeaderText) {
        mHeaderText.setText(mPullLabel);
    }

*/ // Now call the callbackpullToRefreshImpl(); }

public final void refreshing() {
    /*if (null != mHeaderText) {
        mHeaderText.setText(mRefreshingLabel);
    }*/
    if (mUseIntrinsicAnimation) {
        ((AnimationDrawable) mHeaderImage.getDrawable()).start();
    } else {
        // Now call the callback
        refreshingImpl();
    }
    /*if (null != mSubHeaderText) {
        mSubHeaderText.setVisibility(View.GONE);
    }*/
}
public final void releaseToRefresh() {
    /*if (null != mHeaderText) {
        mHeaderText.setText(mReleaseLabel);
    }*/
    // Now call the callback
    releaseToRefreshImpl();
}
public final void reset() {
    /*if (null != mHeaderText) {
        mHeaderText.setText(mPullLabel);
    }*/
    mHeaderImage.setVisibility(View.VISIBLE);
    if (mUseIntrinsicAnimation) {
        ((AnimationDrawable) mHeaderImage.getDrawable()).stop();
    } else {
        // Now call the callback
        resetImpl();
    }
/*  if (null != mSubHeaderText) {
        if (TextUtils.isEmpty(mSubHeaderText.getText())) {
            mSubHeaderText.setVisibility(View.GONE);
        } else {
            mSubHeaderText.setVisibility(View.VISIBLE);
        }
    }*/
}
@Override
public void setLastUpdatedLabel(CharSequence label) {
    setSubHeaderText(label);
}
public final void setLoadingDrawable(Drawable imageDrawable) {
    // Set Drawable
    mHeaderImage.setImageDrawable(imageDrawable);
    mUseIntrinsicAnimation = (imageDrawable instanceof AnimationDrawable);
    // Now call the callback
    onLoadingDrawableSet(imageDrawable);
}
public void setPullLabel(CharSequence pullLabel) {
    mPullLabel = pullLabel;
}
public void setRefreshingLabel(CharSequence refreshingLabel) {
    mRefreshingLabel = refreshingLabel;
}
public void setReleaseLabel(CharSequence releaseLabel) {
    mReleaseLabel = releaseLabel;
}
@Override
public void setTextTypeface(Typeface tf) {/*
    mHeaderText.setTypeface(tf);
*/}
public final void showInvisibleViews() {/*
    if (View.INVISIBLE == mHeaderText.getVisibility()) {
        mHeaderText.setVisibility(View.VISIBLE);
    }
    if (View.INVISIBLE == mHeaderProgress.getVisibility()) {
        mHeaderProgress.setVisibility(View.VISIBLE);
    }
    if (View.INVISIBLE == mHeaderImage.getVisibility()) {
        mHeaderImage.setVisibility(View.VISIBLE);
    }
    if (View.INVISIBLE == mSubHeaderText.getVisibility()) {
        mSubHeaderText.setVisibility(View.VISIBLE);
    }
*/}
/**
 * Callbacks for derivative Layouts
 */
protected abstract int getDefaultDrawableResId();
protected abstract void onLoadingDrawableSet(Drawable imageDrawable);
protected abstract void onPullImpl(float scaleOfLayout);
protected abstract void pullToRefreshImpl();
protected abstract void refreshingImpl();
protected abstract void releaseToRefreshImpl();
protected abstract void resetImpl();
private void setSubHeaderText(CharSequence label) {/*
    if (null != mSubHeaderText) {
        if (TextUtils.isEmpty(label)) {
            mSubHeaderText.setVisibility(View.GONE);
        } else {
            mSubHeaderText.setText(label);
            // Only set it to Visible if we're GONE, otherwise VISIBLE will
            // be set soon
            if (View.GONE == mSubHeaderText.getVisibility()) {
                mSubHeaderText.setVisibility(View.VISIBLE);
            }
        }
    }
*/}
private void setSubTextAppearance(int value) {/*
    if (null != mSubHeaderText) {
        mSubHeaderText.setTextAppearance(getContext(), value);
    }
*/}
private void setSubTextColor(ColorStateList color) {/*
    if (null != mSubHeaderText) {
        mSubHeaderText.setTextColor(color);
    }
*/}
private void setTextAppearance(int value) {/*
    if (null != mHeaderText) {
        mHeaderText.setTextAppearance(getContext(), value);
    }
    if (null != mSubHeaderText) {
        mSubHeaderText.setTextAppearance(getContext(), value);
    }
*/}
private void setTextColor(ColorStateList color) {/*
    if (null != mHeaderText) {
        mHeaderText.setTextColor(color);
    }
    if (null != mSubHeaderText) {
        mSubHeaderText.setTextColor(color);
    }
*/}
}

5,修改雞肋PullToRefreshBase.java

PullToRefreshBase.java
            
           

相關推薦

修改pulltorefresh 重新整理載入顯示

1,在anim目錄下建立動畫 2,生產自己的頭佈局 <?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/a

當scrollview巢狀多recyclerview時如何實現整個頁面的重新整理載入

最近做的一個專案中有個佈局比較複雜一點,整個頁面是個srollview裡面又嵌套了幾個recycview,剛開始是有的滑動衝突卡頓的問題,通過如下方法解決了 mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(),

使用PullToRefresh實現重新整理載入

PullToRefresh是一套實現非常好的下拉重新整理庫,它支援: 1.ListView 2.ExpandableListView 3.GridView 4.WebView 等多種常用的需要重新整理的View型別,而且使用起來也十分方便。 (下載地址:https://gi

[log] vue使用Mint元件實現重新整理載入

https://mint-ui.github.io/docs/#/zh-cn2/loadmore 使用的vue <mt-loadmore :top-method="loadTop" :bottom

微信小程式重新整理載入

example One:如果所有頁面都要開啟下拉重新整理功能: aap.json中: "window":{       "enablePullDownRefresh":true, //開啟下拉重新整理功能       "navigatio

十月專案小結(Recycler重新整理分頁載入

Recycler上拉分頁載入、下拉重新整理 該需求採用RecyclerView、SwipeRefreshLayout以及第三方外掛BRVAH結合使用方式完成,SwipeRefreshLayout完成下拉重新整理、BRVAH完成上拉分頁載入 build.gradle 配置說明

微信小程式重新整理載入

下拉重新整理: (1)直接呼叫onPullDownRefresh:function()事件,首先設定app.js以及有該需求的頁面json檔案中的 “enablePullDownRefresh”: true, //允許下拉重新整理 “backgroundTextStyle”: “dar

Apicloud——重新整理載入

2018-12-07  13:18:21 非Apicloud中的外掛 1 <!doctype html> 2 <html> 3 4 <head> 5 <meta charset="utf-8"> 6

Android簡單的重新整理載入

先匯入第三方的東西 下載地址 匯入後,就和你的專案聯絡起來 佈局程式碼(activity_pull_to_refresh_action.xml) <?xml version="1.0" encoding="utf-8"?> <Lin

vue better-scroll 使用 重新整理載入

我的目的是為了實現列表的下拉重新整理、上拉載入,所以選擇了better-scroll這個庫。 用好這個庫,需要理解下面說明 必須包含兩個大的div,外層和內層div 外層div設定可視的大小(寬或者高)-有限制寬或高 內層div,包裹整個可以滾動的部分 內層d

最全的使用RecyclerView實現重新整理載入更多

前言:            縱觀多數App,下拉重新整理和上拉載入更多是很常見的功能,但是谷歌官方只有一個SwipeRefreshLayout用來下拉重新整理,上拉載入更多還要自己做。      本篇文章基於RecyclerView簡單封裝了這兩個操作,下拉重

android smartRefresh重新整理載入

1.遠端依賴  compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.5.1' 2.佈局中使用 <com.scwang.smartrefresh.layout.SmartRefreshLayout androi

MUi重新整理載入click事件失效問題

今天應用MUi的上拉載入更多方法後,發現給li元素註冊點選click事件沒有反應。 最後折騰半個小時發現一個方法,用mui.on( )新增事件監聽,用tap代替click事件即可解決 mui("#ulId").on("tap","li",function(){ // 邏輯程式碼

TwinklingRefreshLayout 簡單實現實現重新整理載入

支援下拉重新整理和上拉載入的RefreshLayout,自帶越界回彈效果,支援RecyclerView,AbsListView,ScrollView,WebView 本文以ListView為例,實現上拉重新整理和下拉載入,其他的就不在舉例,原理是一樣的。 先看一下效果(效

Android重新整理載入

先看看XML佈局檔案,下拉重新整理和上拉載入哪個在外層並沒有什麼影響。最裡面嵌套了一個RecycleView。 <android.support.v4.widget.SwipeRefreshLayout     android:id="@+id/gridswipre

template-web.js 結合dropload.min.js外掛實現重新整理載入

//引入js,所需要的js已經上傳到個人資源 <script type="text/javascript" src="/web/home/js/template-web.js"></script> <link href="/web/h

vue 重新整理載入公共元件

這個效果也是...只能說我這個上拉載入的時候也要有彈性的那種感覺,所以我在別人的元件中修改了一下下,但是也不是特別的理想吧,希望你們還能多多指出好讓我加以更正,我們共同學習,好不,哈哈, 我先附上我看到別人網上寫的,我覺得人家寫的是蠻不錯的。 https://www.cnblogs.com/sichaoy

用Recyclerview實現列表分組、重新整理以及載入--原始碼

這裡放上之前整理的一篇文章的完整原始碼,因為是從專案中抽取出來的,也沒有單獨再寫一個demo,希望需要的小夥伴能結合之前寫的一篇文章,理解實現原理,而不要簡單的想要直接copy拿來用,這裡是博文地址: import android.content.Con

better-scroll實現重新整理載入更多(巨簡單...)

1、廢話少說,先看看移動端的列表頁面 (1)正常瀏覽 (2)下拉重新整理中 (3)下拉重新整理結束 (4) 上拉載入 (5)上拉 載入中 3、網上也有一些基本使用教程,這裡就不一一累贅,下

一個簡單好用的重新整理載入控制元件

*本篇文章已授權微信公眾號 guolin_blog (郭霖)獨家釋出 有更新: 最新的庫版本為1.0.2(相容舊版本,舊版本是1.0.0),完整的庫地址: compile'com.zt.maven.widget:refreshview:1.0.2