Android下拉刷新上拉加载简单的实现方法

项目中需要用到Android下拉刷新和上拉加载;所以学习了一个很简单的很方便的一个例子;自己也写过下拉刷新和上拉加载的功能;但是如果每个界面都要实现这个功能的话非常的麻烦;所以学习了别人很好的demo;然后分享一下;

我的学习步骤;

在网上下载demo;然后把必要的导入到项目中;

在此附上下载源码

------------------------------------------分割线------------------------------------------

免费下载地址在

用户名与密码都是

具体下载目录在 /2015年资料/6月/12日/Android下拉刷新上拉加载简单的实现方法/

下载方法见

------------------------------------------分割线------------------------------------------

所有的源代码如下;

XListViewFooter类

/**
 * @file XFooterView.java
 * @create Mar 31, 2012 9:33:43 PM
 * @author Maxwin
 * @description XListView's footer
 */
package me.maxwin.view;

import me.maxwin.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class XListViewFooter extends LinearLayout {
 public final static int STATE_NORMAL = 0;
 public final static int STATE_READY = 1;
 public final static int STATE_LOADING = 2;

private Context mContext;

private View mContentView;
 private View mProgressBar;
 private TextView mHintView;
 
 public XListViewFooter(Context context) {
  super(context);
  initView(context);
 }
 
 public XListViewFooter(Context context, AttributeSet attrs) {
  super(context, attrs);
  initView(context);
 }


 public void setState(int state) {
  mHintView.setVisibility(View.INVISIBLE);
  mProgressBar.setVisibility(View.INVISIBLE);
  mHintView.setVisibility(View.INVISIBLE);
  if (state == STATE_READY) {
   mHintView.setVisibility(View.VISIBLE);
   mHintView.setText(R.string.xlistview_footer_hint_ready);
  } else if (state == STATE_LOADING) {
   mProgressBar.setVisibility(View.VISIBLE);
  } else {
   mHintView.setVisibility(View.VISIBLE);
   mHintView.setText(R.string.xlistview_footer_hint_normal);
  }
 }
 
 public void setBottomMargin(int height) {
  if (height < 0) return ;
  LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)mContentView.getLayoutParams();
  lp.bottomMargin = height;
  mContentView.setLayoutParams(lp);
 }
 
 public int getBottomMargin() {
  LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)mContentView.getLayoutParams();
  return lp.bottomMargin;
 }
 
 
 /**
  * normal status
  */
 public void normal() {
  mHintView.setVisibility(View.VISIBLE);
  mProgressBar.setVisibility(View.GONE);
 }
 
 
 /**
  * loading status
  */
 public void loading() {
  mHintView.setVisibility(View.GONE);
  mProgressBar.setVisibility(View.VISIBLE);
 }
 
 /**
  * hide footer when disable pull load more
  */
 public void hide() {
  LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)mContentView.getLayoutParams();
  lp.height = 0;
  mContentView.setLayoutParams(lp);
 }
 
 /**
  * show footer
  */
 public void show() {
  LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)mContentView.getLayoutParams();
  lp.height = LayoutParams.WRAP_CONTENT;
  mContentView.setLayoutParams(lp);
 }
 
 private void initView(Context context) {
  mContext = context;
  LinearLayout moreView = (LinearLayout)LayoutInflater.from(mContext).inflate(R.layout.xlistview_footer, null);
  addView(moreView);
  moreView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
 
  mContentView = moreView.findViewById(R.id.xlistview_footer_content);
  mProgressBar = moreView.findViewById(R.id.xlistview_footer_progressbar);
  mHintView = (TextView)moreView.findViewById(R.id.xlistview_footer_hint_textview);
 }
 
 
}

XListViewHeader类

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/7f9af977b63f35b67d5952bd2a6ab86c.html