新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > Android常用控件之下拉刷新Wifi列表

        Android常用控件之下拉刷新Wifi列表

        作者: 時間:2016-09-12 來源:網絡 收藏

        本文引用地址:http://www.104case.com/article/201609/304586.htm

        界面

        關鍵代碼

        下拉列表類

        package com.example.dropdownrefresh.ui;

        import java.text.SimpleDateFormat;

        import java.util.Date;

        import com.example.dropdownrefresh.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.animation.LinearInterpolator;

        import android.view.animation.RotateAnimation;

        import android.widget.AbsListView;

        import android.widget.AbsListView.OnScrollListener;

        import android.widget.BaseAdapter;

        import android.widget.ImageView;

        import android.widget.LinearLayout;

        import android.widget.ListView;

        import android.widget.ProgressBar;

        import android.widget.TextView;

        /**

        * 下拉列表類

        * @author Administrator

        *

        */

        public class DropdownListView 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;

        // 實際的padding的距離與界面上偏移距離的比例

        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;

        // 用于保證startY的值在一個完整的touch事件中只被記錄一次

        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 DropdownListView(Context context) {

        super(context);

        // TODO Auto-generated constructor stub

        init(context);

        }

        public DropdownListView(Context context, AttributeSet attrs) {

        super(context, attrs);

        init(context);

        }

        private void init(Context context) {

        setCacheColorHint(context.getResources().getColor(R.color.transparent));

        inflater = LayoutInflater.from(context);

        headView = (LinearLayout) inflater.inflate(R.layout.head, 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(250);

        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(200);

        reverseAnimation.setFillAfter(true);

        state = DONE;


        上一頁 1 2 3 4 5 下一頁

        關鍵詞:

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 金门县| 扎鲁特旗| 高尔夫| 武隆县| 兴山县| 都安| 桂平市| 西充县| 青浦区| 祁阳县| 环江| 陈巴尔虎旗| 诏安县| 聊城市| 湟源县| 陇川县| 酒泉市| 抚宁县| 昭苏县| 巴青县| 阳信县| 讷河市| 东港市| 庄浪县| 治县。| 嘉荫县| 花莲县| 福泉市| 定兴县| 凤翔县| 武冈市| 甘泉县| 合肥市| 贺州市| 丰镇市| 嫩江县| 舟山市| 双峰县| 汝南县| 保山市| 安西县|