修改pulltorefresh 下拉刷新个上拉加载的显示

来源:互联网 发布:pdf排版软件 编辑:程序博客网 时间:2024/05/21 19:42

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
LoadingLayout createLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
        switch (this) {
            case ROTATE:
            default:
                return new MyLoadingLayOut(context, mode, scrollDirection, attrs);
                //return new RotateLoadingLayout(context, mode, scrollDirection, attrs);
            case FLIP:
                return new FlipLoadingLayout(context, mode, scrollDirection, attrs);
        }
    }

 

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 考到不好的大学怎么办 考的大学不理想怎么办 只考上二本大学怎么办 w7电脑中病毒了怎么办 电脑中病毒了该怎么办 泰迪呼吸急促怎么办啊 狗狗呼吸急促是怎么办 狗狗着凉了呕吐怎么办 狗鼻子流黄鼻涕怎么办 刚出生婴儿睡觉不踏实怎么办 有人溺水后你该怎么办 借钱不还怎么办没欠条 私人欠货款不还怎么办 公司欠货款不还怎么办 两个人离婚一方不同意怎么办 比亚迪l3油耗高怎么办 u盘密码忘记了怎么办 主板没有m.2接口怎么办 点痣留下了疤怎么办 危险三角区长痘痘怎么办 挤了危险三角区怎么办 三角区长痘挤了怎么办 三角区发红长痘怎么办 激光祛斑碰水了怎么办 激光打痣留下坑怎么办 点痣之后留下坑怎么办 去痣留下的红印怎么办 激光点痦子留疤怎么办 激光点痣的疤痕怎么办 做完眉毛碰水了怎么办 脸上疤掉了有坑怎么办 结痂不小心抠掉怎么办 脸上肉松弛怎么办19岁 点痣留下来的疤怎么办 激光祛斑的红印怎么办 脸上疤掉了红印怎么办 痘痘发炎了红肿怎么办 脸上的斑越来越多了怎么办 点痣留下的疤痕怎么办 额头又高又大怎么办 脸太长额头太高怎么办