您的位置:首页 > 其它

XlistView4(脚部刷新)

2016-03-23 20:22 253 查看
脚部实现上拉刷新

package com.example.listviewshangxia;
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);
}

/**
* 当禁用拉加载更多隐藏底部视图
*/
public void hide() {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mContentView
.getLayoutParams();
lp.height = 0;
mContentView.setLayoutParams(lp);
}

/**
* 显示底部视图
*/
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);
}

}



xml代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<RelativeLayout
android:id="@+id/xlistview_footer_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp" >

<ProgressBar
android:id="@+id/xlistview_footer_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible" />

<TextView
android:id="@+id/xlistview_footer_hint_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/xlistview_footer_hint_normal" />
</RelativeLayout>

</LinearLayout>


styles中的配置

<!-- 下拉刷新,上拉加载更多 -->
<string name="xlistview_header_hint_normal">下拉刷新</string>
<string name="xlistview_header_hint_ready">松开刷新数据</string>
<string name="xlistview_header_hint_loading">正在加载...</string>
<string name="xlistview_header_last_time">上次更新时间:</string>
<string name="xlistview_footer_hint_normal">查看更多</string>
<string name="xlistview_footer_hint_ready">松开载入更多</string>


color.xml 的设置

<?xml version="1.0" encoding="utf-8"?>
<resources>

<color name="transparent">#00000000</color>
<color name="yellow">#ffcc00</color>
<color name="yellow_back">#FFEDBB</color>
<color name="yellow_test">#A25B00</color>
<color name="white">#ffffff</color>
<color name="black">#cc000000</color>
<color name="news_list_black">#333333</color>
<color name="news_list_time">#969696</color>
<color name="news_test">#5e5e5e</color>
<color name="third_color">#C9C9C9</color>
<color name="blue">#0000ff</color>
<color name="red">#ff0000</color>
<color name="light_red">#ff3300</color>
<color name="green">#04c004</color>
<color name="choice_house_press">#86d3ef</color>
<color name="gold">#ffd700</color>
<color name="orange">#ffa500</color>
<color name="brown">#a52a2a</color>
<color name="deepskyblue">#00bfff</color>
<color name="darkblue">#00008b</color>
<color name="gray">#ffe7e7e7</color>
<color name="light_gray">#EFEFEF</color>
<color name="light_lanse">#33ffff</color>
<!-- 深灰色 -->
<color name="gray1">#5c615d</color>
<!-- 灰色 -->
<color name="gray2">#949393</color>
<!-- 淡灰色 -->
<color name="gray3">#CCCCCC</color>
<!-- 淡淡灰色 -->
<color name="gray4">#e5e5e5</color>
<color name="bg_app">#efefef</color>
<color name="bg_actionbar">#52c83b</color>
<color name="actionbar_selected">#298a24</color>
<color name="item_checked">#202020</color>
<color name="item_text_checked">#d4bc7c</color>
<color name="list_divider">#595959</color>
<color name="bg_left_tabs">#3d3d3d</color>
<color name="dialog_title_divider">#efefef</color>
<color name="text_default">#B4B4B4</color>
<color name="light_yellow">#fffae2</color>
<color name="more_footer_text_color">#33cccc</color>
<color name="more_footer_text_color1">#f3f3f3</color>

</resources>


图片资源



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: