转自http://www.linuxidc.com/Linux/2012-08/67207.htm
主布局main.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="fill_parent"
- android:orientation="vertical" >
-
- <HorizontalScrollView
- android:id="@+id/horizontalscrollview"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@drawable/item"
- android:fadingEdge="@null"
- android:scrollbars="none" >
-
- <LinearLayout
- android:id="@+id/linearlayout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal"
- >
- </LinearLayout>
- </HorizontalScrollView>
-
- <android.support.v4.view.ViewPager
- android:id="@+id/viewpaper"
- android:layout_width="fill_parent"
- android:layout_height="match_parent"
- android:layout_weight="1" >
- </android.support.v4.view.ViewPager>
-
- </LinearLayout>
2,接着看看QQonline.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="fill_parent"
- android:orientation="vertical"
- android:background="@drawable/image2">
-
-
- <ExpandableListView
- android:id="@+id/elistview"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="5dp"
-
-
- />
-
- </LinearLayout>
3.接着看看下拉更新的布局pullrefresh.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="fill_parent"
- android:background="@drawable/image1"
- android:orientation="vertical" >
-
- <com.wang.pullrefresh.MyListView
- android:id="@+id/listView"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent" />
-
-
- </LinearLayout>
4.下拉更新过程实现的布局refresh.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/head_contentLayout"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:paddingLeft="30dp" >
-
- <FrameLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_centerVertical="true" >
-
- <ImageView
- android:id="@+id/head_arrowImageView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:src="@drawable/down" />
-
- <ProgressBar
- android:id="@+id/head_progressBar"
- style="?android:attr/progressBarStyleSmall"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:visibility="gone" />
- </FrameLayout>
-
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:gravity="center_horizontal"
- android:orientation="vertical" >
-
- <TextView
- android:id="@+id/head_tipsTextView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="下拉可以刷新"
- android:textSize="15dp" />
-
- <TextView
- android:id="@+id/head_lastUpdatedTextView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="上次更新时间:"
- android:textSize="12dp" />
- </LinearLayout>
- </RelativeLayout>
-
- </LinearLayout>
5.下拉更新的列表显示的布局list_item.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:orientation="horizontal" >
-
- <ImageView
- android:id="@+id/imageView_item"
- android:layout_width="60dp"
- android:layout_height="60dp"
- android:layout_marginLeft="5dp"
- android:src="@drawable/qq" />
-
- <TextView
- android:id="@+id/textView_item"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="10dp"
- android:textColor="#FFFFFF"
- />
-
- </LinearLayout>
6.接着看看还没有完善的QQ聊天信息的布局main3.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="fill_parent"
- android:orientation="vertical"
- android:background="@drawable/image3">
-
-
-
- </LinearLayout>
7.接着看看主活动的实现过程ViewPaper1Activity.java
- package com.wang;
-
- import java.util.ArrayList;
-
- import android.app.ActivityGroup;
- import android.content.Intent;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.drawable.BitmapDrawable;
- import android.os.Bundle;
- import android.support.v4.view.PagerAdapter;
- import android.support.v4.view.ViewPager;
- import android.support.v4.view.ViewPager.OnPageChangeListener;
- import android.view.Gravity;
- import android.view.View;
- import android.view.Window;
- import android.view.WindowManager;
- import android.view.View.OnClickListener;
- import android.widget.HorizontalScrollView;
- import android.widget.LinearLayout;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.TextView;
- import android.widget.LinearLayout.LayoutParams;
-
- public class ViewPaper1Activity extends ActivityGroup implements
- OnClickListener {
- private RadioGroup radioGroup;
-
- private String array[] = { "QQ空间", "QQ", "QQ消息" };
- private LinearLayout linearLayout;
- private ArrayList<TextView> textViews;
- private ViewPager viewPager;
- private ArrayList<View> pageViews;
- private HorizontalScrollView horizontalScrollView;
-
-
-
-
-
-
- void InItView() {
-
- pageViews = new ArrayList<View>();
-
-
-
- View view1 = getLocalActivityManager().startActivity("main1",
- new Intent(this, pullrefreshtest.class)).getDecorView();
- View view2 = getLocalActivityManager().startActivity("main2",
- new Intent(this, QQonline.class)).getDecorView();
- View view3 = getLocalActivityManager().startActivity("main3",
- new Intent(this, main3.class)).getDecorView();
-
- pageViews.add(view1);
- pageViews.add(view2);
- pageViews.add(view3);
- }
-
-
-
-
- void InItTitle() {
-
- int width = getWindowManager().getDefaultDisplay().getWidth() / 3;
-
- for (int i = 0; i < array.length; i++) {
-
- RadioButton radioButton = new RadioButton(this, null);
- radioButton.setText(array[i]);
- radioButton.setWidth(width);
- radioButton.setHeight(70);
-
- radioButton.setGravity(Gravity.CENTER);
-
- radioGroup.addView(radioButton);
- }
- }
-
-
-
-
- void initTextView() {
-
- textViews = new ArrayList<TextView>();
-
- int width = getWindowManager().getDefaultDisplay().getWidth() / 3;
- int height = 60;
- for (int i = 0; i < array.length; i++) {
- TextView textView = new TextView(this);
- textView.setText(array[i]);
- textView.setTextSize(17);
- textView.setWidth(width);
- textView.setHeight(height - 30);
- textView.setGravity(Gravity.CENTER);
- textView.setId(i);
-
- textView.setOnClickListener(this);
- textViews.add(textView);
- LinearLayout.LayoutParams layoutParams = new LayoutParams(
- LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
- layoutParams.width = 1;
- layoutParams.height = height - 40;
- layoutParams.gravity = Gravity.CENTER;
-
- linearLayout.addView(textView);
-
- }
- }
-
-
-
-
- public void select(int id) {
- for (int i = 0; i < array.length; i++) {
- if (id == i) {
-
- Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
- R.drawable.itembg);
-
- textViews.get(id).setBackgroundDrawable(
- new BitmapDrawable(bitmap));
- viewPager.setCurrentItem(i);
- }
-
- else {
- textViews.get(i).setBackgroundDrawable(new BitmapDrawable());
- }
- }
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
-
- this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
-
- setContentView(R.layout.main);
-
- linearLayout = (LinearLayout) findViewById(R.id.linearlayout);
- viewPager = (ViewPager) findViewById(R.id.viewpaper);
- horizontalScrollView = (HorizontalScrollView) findViewById(R.id.horizontalscrollview);
-
- initTextView();
- select(0);
- InItView();
-
- viewPager.setAdapter(new PagerAdapter() {
-
- public int getCount() {
- return pageViews.size();
- }
-
- @Override
- public boolean isViewFromObject(View view, Object object) {
- return view == object;
- }
-
- @Override
- public int getItemPosition(Object object) {
-
- return super.getItemPosition(object);
- }
-
- @Override
- public void destroyItem(View view, int id, Object arg2) {
-
- ((ViewPager) view).removeView(pageViews.get(id));
- }
-
-
- @Override
- public Object instantiateItem(View view, int id) {
- ((ViewPager) view).addView(pageViews.get(id));
- return pageViews.get(id);
- }
-
- });
-
- viewPager.setOnPageChangeListener(new OnPageChangeListener() {
-
- @Override
- public void onPageSelected(int arg0) {
- select(arg0);
- }
-
- @Override
- public void onPageScrolled(int arg0, float arg1, int arg2) {
-
- }
-
- @Override
- public void onPageScrollStateChanged(int arg0) {
-
- }
- });
- }
-
- @Override
- public void onClick(View v) {
- select(v.getId());
- }
-
- }
8.接着看看QQonline.java 的实现
- package com.wang;
-
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.ContextMenu;
- import android.view.View;
- import android.view.Window;
- import android.view.WindowManager;
- import android.view.ContextMenu.ContextMenuInfo;
- import android.widget.ExpandableListAdapter;
- import android.widget.ExpandableListView;
- import android.widget.Toast;
- import android.widget.ExpandableListView.OnChildClickListener;
- import android.widget.ExpandableListView.OnGroupClickListener;
- import android.widget.ExpandableListView.OnGroupCollapseListener;
- import android.widget.ExpandableListView.OnGroupExpandListener;
-
- public class QQonline extends Activity {
-
- public void onCreateContextMenu(ContextMenu menu, View v,
- ContextMenuInfo menuInfo) {
-
- super.onCreateContextMenu(menu, v, menuInfo);
-
-
- ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
-
- int type = ExpandableListView
- .getPackedPositionType(info.packedPosition);
-
- int group = ExpandableListView
- .getPackedPositionGroup(info.packedPosition);
-
- int child = ExpandableListView
- .getPackedPositionGroup(info.packedPosition);
-
- Toast.makeText(QQonline.this,
- "类型 =" + type + " 分组:" + group + " 子选项:" + child,
- Toast.LENGTH_LONG).show();
-
- }
-
- private ExpandableListView eListView = null;
- private ExpandableListAdapter adapter = null;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
-
-
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
-
- this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
-
- super.onCreate(savedInstanceState);
- super.setContentView(R.layout.qqonline);
-
-
- this.eListView = (ExpandableListView) findViewById(R.id.elistview);
-
-
- adapter = new myExpendableadapler(this);
-
- this.eListView.setAdapter(this.adapter);
-
-
- super.registerForContextMenu(this.eListView);
-
-
- this.eListView.setOnChildClickListener(new ChildClickListener());
- this.eListView.setOnGroupClickListener(new GroupClickListener());
- this.eListView.setOnGroupExpandListener(new GroupExpandListener());
- this.eListView.setOnGroupCollapseListener(new GroupCollapseListener());
-
- }
-
-
- private class ChildClickListener implements OnChildClickListener {
-
- public boolean onChildClick(ExpandableListView parent, View v,
- int groupPosition, int childPosition, long id) {
- Toast
- .makeText(
- QQonline.this,
- "子选项被选中,所的组:" + groupPosition + " 子选项的位置:"
- + childPosition, Toast.LENGTH_LONG).show();
- return false;
- }
-
- }
-
-
- private class GroupClickListener implements OnGroupClickListener {
-
- public boolean onGroupClick(ExpandableListView parent, View v,
- int groupPosition, long id) {
- Toast.makeText(QQonline.this, "分组选项被选中,所在组: " + groupPosition,
- Toast.LENGTH_LONG).show();
- return false;
- }
-
- }
-
-
- private class GroupExpandListener implements OnGroupExpandListener {
-
- public void onGroupExpand(int groupPosition) {
-
- Toast.makeText(QQonline.this, "打开分组,所在组:" + groupPosition,
- Toast.LENGTH_LONG).show();
- }
-
- }
-
-
- private class GroupCollapseListener implements OnGroupCollapseListener {
-
- public void onGroupCollapse(int groupPosition) {
- Toast.makeText(QQonline.this, "关闭分组,所在组:" + groupPosition,
- Toast.LENGTH_LONG).show();
- }
-
- }
-
- }
9.接着需要myExpendableadapler.java
- package com.wang;
-
- import android.content.Context;
- import android.view.Gravity;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.AbsListView;
- import android.widget.BaseExpandableListAdapter;
- import android.widget.TextView;
-
- public class myExpendableadapler extends BaseExpandableListAdapter {
-
- private String[] group = new String[] { "在线好友", "高中同学", "南阳理工同学", "寝室哥们" };
-
- private String[][] child = new String[][] {
- { "李彦宏", "马云", "雷军", "周鸿祎", "唐骏", "赵威威", "李冕", "马海刚", "李斌", "刘洪刚",
- "马玉龙", "刘慧敏", "王文龙" },
- { "赵威威", "李冕", "马海刚", "李斌", "刘洪刚", "马玉龙", "刘慧敏", "王文龙" },
- { "张紫阳", "王亚光", "刘一鸣", "崔芳芳", "董卫杰", "刘永乐" },
- { "武云册", "王俊伟", "王杰", "付永振", "杜新峰", "应志超" } };
- private Context context = null;
-
-
- public myExpendableadapler(Context context) {
-
- this.context = context;
- }
-
- public Object getChild(int groupPosition, int childPosition) {
-
- return this.child[groupPosition][childPosition];
- }
-
- public long getChildId(int groupPosition, int childPosition) {
-
- return childPosition;
- }
-
- private TextView buildTextView() {
-
- AbsListView.LayoutParams params = new AbsListView.LayoutParams(
- ViewGroup.LayoutParams.FILL_PARENT, 40);
-
- TextView textView = new TextView(this.context);
- textView.setLayoutParams(params);
-
- textView.setTextSize(15.0f);
- textView.setGravity(Gravity.LEFT + 3);
- textView.setPadding(40, 8, 3, 3);
- return textView;
- }
-
- public View getChildView(int groupPosition, int childPosition,
- boolean isLastChild, View convertView, ViewGroup parent) {
- TextView textView = new TextView(this.context);
-
- textView
- .setText(this.getChild(groupPosition, childPosition).toString());
-
- return textView;
- }
-
-
- public int getChildrenCount(int groupPosition) {
-
- return this.child[groupPosition].length;
- }
-
-
- public Object getGroup(int groupPosition) {
-
- return this.group[groupPosition];
- }
-
-
- public int getGroupCount() {
-
- return this.group.length;
- }
-
-
- public long getGroupId(int groupPosition) {
-
- return groupPosition;
- }
-
- public View getGroupView(int groupPosition, boolean isExpanded,
- View convertView, ViewGroup parent) {
-
- TextView textView = this.buildTextView();
- textView.setText(this.getGroup(groupPosition).toString());
- return textView;
- }
-
-
- public boolean hasStableIds() {
-
- return true;
- }
-
-
- public boolean isChildSelectable(int groupPosition, int childPosition) {
-
- return true;
- }
-
- }
10.有两个界面还没有添加功能pullrefreshtest.java
11.接着是下拉列表更新的实现过程MyListView.java
- package com.wang.pullrefresh;
-
- import java.text.SimpleDateFormat;
- import java.util.Date;
-
- import com.wang.R;
-
- import android.content.Context;
- import android.util.AttributeSet;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.View.MeasureSpec;
- import android.view.animation.LinearInterpolator;
- import android.view.animation.RotateAnimation;
- import android.widget.AbsListView;
- import android.widget.BaseAdapter;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.ListView;
- import android.widget.ProgressBar;
- import android.widget.TextView;
- import android.widget.AbsListView.OnScrollListener;
-
- public class MyListView extends ListView implements OnScrollListener {
-
- private static final String TAG = "listview";
-
- private final static int RELEASE_To_REFRESH = 0;
- private final static int PULL_To_REFRESH = 1;
- private final static int REFRESHING = 2;
- private final static int DONE = 3;
- private final static int LOADING = 4;
-
-
- private final static int RATIO = 3;
-
- private LayoutInflater inflater;
-
- private LinearLayout headView;
-
- private TextView tipsTextview;
- private TextView lastUpdatedTextView;
- private ImageView arrowImageView;
- private ProgressBar progressBar;
-
- private RotateAnimation animation;
- private RotateAnimation reverseAnimation;
-
-
- private boolean isRecored;
-
- private int headContentWidth;
- private int headContentHeight;
-
- private int startY;
- private int firstItemIndex;
-
- private int state;
-
- private boolean isBack;
-
- private OnRefreshListener refreshListener;
-
- private boolean isRefreshable;
-
- public MyListView(Context context) {
- super(context);
-
- init(context);
- }
-
- public MyListView(Context context, AttributeSet attrs) {
- super(context, attrs);
-
- init(context);
- }
-
- private void init(Context context) {
-
-
- inflater = LayoutInflater.from(context);
-
-
- headView = (LinearLayout) inflater.inflate(R.layout.refresh, null);
-
- arrowImageView = (ImageView) headView
- .findViewById(R.id.head_arrowImageView);
-
- arrowImageView.setMinimumWidth(70);
- arrowImageView.setMinimumHeight(50);
-
- progressBar = (ProgressBar) headView
- .findViewById(R.id.head_progressBar);
- tipsTextview = (TextView) headView.findViewById(R.id.head_tipsTextView);
- lastUpdatedTextView = (TextView) headView
- .findViewById(R.id.head_lastUpdatedTextView);
-
-
- measureView(headView);
-
- headContentHeight = headView.getMeasuredHeight();
- headContentWidth = headView.getMeasuredWidth();
-
-
- headView.setPadding(0, -1 * headContentHeight, 0, 0);
- headView.invalidate();
-
-
- Log.v("size", "width:" + headContentWidth + " height:"
- + headContentHeight);
-
-
- addHeaderView(headView, null, false);
-
- setOnScrollListener(this);
-
-
- animation = new RotateAnimation(0, -180,
- RotateAnimation.RELATIVE_TO_SELF, 0.5f,
- RotateAnimation.RELATIVE_TO_SELF, 0.5f);
-
- animation.setInterpolator(new LinearInterpolator());
- animation.setDuration(300);
-
- animation.setFillAfter(true);
-
- reverseAnimation = new RotateAnimation(-180, 0,
- RotateAnimation.RELATIVE_TO_SELF, 0.5f,
- RotateAnimation.RELATIVE_TO_SELF, 0.5f);
-
- reverseAnimation.setInterpolator(new LinearInterpolator());
- reverseAnimation.setDuration(300);
-
- reverseAnimation.setFillAfter(true);
-
-
- state = DONE;
-
- isRefreshable = false;
- }
-
-
- public void onScroll(AbsListView arg0, int firstVisiableItem, int arg2,
- int arg3) {
- firstItemIndex = firstVisiableItem;
- }
-
-
-
-
- public void onScrollStateChanged(AbsListView arg0, int arg1) {
- }
-
-
- public boolean onTouchEvent(MotionEvent event) {
-
-
- if (isRefreshable) {
-
- switch (event.getAction()) {
-
-
- case MotionEvent.ACTION_DOWN:
- if (firstItemIndex == 0 && !isRecored) {
- isRecored = true;
- startY = (int) event.getY();
- Log.v(TAG, "在下拉的时候记录当前位置‘");
- }
- break;
-
-
- case MotionEvent.ACTION_UP:
-
- if (state != REFRESHING && state != LOADING) {
- if (state == DONE) {
-
- }
- if (state == PULL_To_REFRESH) {
- state = DONE;
- changeHeaderViewByState();
-
- Log.v(TAG, "由下拉刷新状态,到done状态");
- }
- if (state == RELEASE_To_REFRESH) {
- state = REFRESHING;
- changeHeaderViewByState();
- onRefresh();
-
- Log.v(TAG, "由松开刷新状态,到done状态");
- }
- }
-
- isRecored = false;
- isBack = false;
-
- break;
-
-
- case MotionEvent.ACTION_MOVE:
- int tempY = (int) event.getY();
-
- if (!isRecored && firstItemIndex == 0) {
- Log.v(TAG, "在move时候记录下位置");
- isRecored = true;
- startY = tempY;
- }
-
- if (state != REFRESHING && isRecored && state != LOADING) {
-
-
-
-
-
- if (state == RELEASE_To_REFRESH) {
-
- setSelection(0);
-
-
- if (((tempY - startY) / RATIO < headContentHeight)
- && (tempY - startY) > 0) {
- state = PULL_To_REFRESH;
- changeHeaderViewByState();
-
- Log.v(TAG, "由松开刷新状态转变到下拉刷新状态");
- }
-
- else if (tempY - startY <= 0) {
- state = DONE;
-
- changeHeaderViewByState();
-
- Log.v(TAG, "由松开刷新状态转变到done状态");
- } else {
- }
- }
-
- if (state == PULL_To_REFRESH) {
-
- setSelection(0);
-
-
- if ((tempY - startY) / RATIO >= headContentHeight) {
- state = RELEASE_To_REFRESH;
- isBack = true;
-
- changeHeaderViewByState();
-
- Log.v(TAG, "由done或者下拉刷新状态转变到松开刷新");
- }
-
- else if (tempY - startY <= 0) {
- state = DONE;
-
- changeHeaderViewByState();
-
- Log.v(TAG, "由DOne或者下拉刷新状态转变到done状态");
- }
- }
-
-
- if (state == DONE) {
- if (tempY - startY > 0) {
- state = PULL_To_REFRESH;
-
- changeHeaderViewByState();
- }
- }
-
-
- if (state == PULL_To_REFRESH) {
- headView.setPadding(0, -1 * headContentHeight
- + (tempY - startY) / RATIO, 0, 0);
-
- }
-
-
- if (state == RELEASE_To_REFRESH) {
- headView.setPadding(0, (tempY - startY) / RATIO
- - headContentHeight, 0, 0);
- }
-
- }
-
- break;
- }
- }
-
- return super.onTouchEvent(event);
- }
-
-
- private void changeHeaderViewByState() {
-
- switch (state) {
-
-
- case RELEASE_To_REFRESH:
-
- arrowImageView.setVisibility(View.VISIBLE);
- progressBar.setVisibility(View.GONE);
- tipsTextview.setVisibility(View.VISIBLE);
- lastUpdatedTextView.setVisibility(View.VISIBLE);
-
-
- arrowImageView.clearAnimation();
- arrowImageView.startAnimation(animation);
-
- tipsTextview.setText("松开既可刷新");
-
- Log.v(TAG, "当前状态,松开即可刷新");
- break;
-
-
- case PULL_To_REFRESH:
-
- progressBar.setVisibility(View.GONE);
- tipsTextview.setVisibility(View.VISIBLE);
- lastUpdatedTextView.setVisibility(View.VISIBLE);
-
- arrowImageView.clearAnimation();
- arrowImageView.setVisibility(View.VISIBLE);
-
- if (isBack) {
- isBack = false;
-
- arrowImageView.clearAnimation();
- arrowImageView.startAnimation(reverseAnimation);
-
- tipsTextview.setText("下拉刷新");
- } else {
- tipsTextview.setText("下拉刷新");
- }
- Log.v(TAG, "当前状态,下拉刷新");
- break;
-
- case REFRESHING:
-
- headView.setPadding(0, 0, 0, 0);
-
- progressBar.setVisibility(View.VISIBLE);
-
- arrowImageView.clearAnimation();
- arrowImageView.setVisibility(View.GONE);
- tipsTextview.setText("正在刷新...");
- lastUpdatedTextView.setVisibility(View.VISIBLE);
-
- Log.v(TAG, "当前状态,正在刷新...");
- break;
- case DONE:
-
- headView.setPadding(0, -1 * headContentHeight, 0, 0);
-
- progressBar.setVisibility(View.GONE);
-
- arrowImageView.clearAnimation();
- arrowImageView.setImageResource(R.drawable.down);
- tipsTextview.setText("下拉刷新");
- lastUpdatedTextView.setVisibility(View.VISIBLE);
-
- Log.v(TAG, "当前状态");
- break;
- }
- }
-
- public void setonRefreshListener(OnRefreshListener refreshListener) {
- this.refreshListener = refreshListener;
- isRefreshable = true;
- }
-
- public interface OnRefreshListener {
- public void onRefresh();
- }
-
-
- public void onRefreshComplete() {
- state = DONE;
-
- SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
- String date = format.format(new Date());
- lastUpdatedTextView.setText("最近更新:" + date);
- changeHeaderViewByState();
- }
-
- private void onRefresh() {
- if (refreshListener != null) {
- refreshListener.onRefresh();
- }
- }
-
-
- private void measureView(View child) {
-
- ViewGroup.LayoutParams p = child.getLayoutParams();
- if (p == null) {
-
- p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
- }
-
-
- int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0 + 0, p.width);
- int lpHeight = p.height;
- int childHeightSpec;
- if (lpHeight > 0) {
-
- childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight,
- MeasureSpec.EXACTLY);
- } else {
- childHeightSpec = MeasureSpec.makeMeasureSpec(0,
- MeasureSpec.UNSPECIFIED);
- }
-
- child.measure(childWidthSpec, childHeightSpec);
- }
-
- public void setAdapter(BaseAdapter adapter) {
-
- SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
- String date = format.format(new Date());
- lastUpdatedTextView.setText("最近更新:" + date);
- super.setAdapter(adapter);
- }
-
- }
12.接着是没有添加聊天功能的main3.java
- package com.wang;
-
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.ImageView;
-
- public class main3 extends Activity {
- protected void onCreate(Bundle savedInstanceState) {
-
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main3);
- }
-
- }
13.亲,由于用到Activity,要注意注册哦!!
- <activity android:name=".pullrefreshtest"></activity>
- <activity android:name=".QQonline"></activity>
- <activity android:name=".main3"></activity>
14.最后,还有一个重要的问题,本程序需要第三方jar包的支持,所以呢还需要导入第三方android-support-v4.jar包, 不会的参考 http://www.linuxidc.com/Linux/2012-08/67213.htm
下载地址
免费下载地址在 http://linux.linuxidc.com/
用户名与密码都是www.linuxidc.com
具体下载目录在 /2012年资料/8月/3日/Android模仿QQ的左右滑动切换界面和下拉更新的效果/android-support-v4.jar包
15,这样过后就可以看到运行效果咯: 第一张是下拉刷新时候的界面,第二张是松开即可刷新时候的图片,第三张是刷新后的内容,第四张的QQ联系人的界面,第五张是还没有完善聊天消息的界面,第六张是左右滑动切换界面的实现效果