<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > Android常用控件之下拉刷新Wifi列表

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

          作者: 時(shí)間:2016-09-12 來源:網(wǎng)絡(luò) 收藏

          isRefreshable = false;

          }

          @Override

          public void onScroll(AbsListView arg0, int firstVisiableItem, int arg2,

          int arg3) {

          // TODO Auto-generated method stub

          firstItemIndex = firstVisiableItem;

          }

          @Override

          public void onScrollStateChanged(AbsListView view, int scrollState) {

          // TODO Auto-generated method stub

          }

          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, 在down時(shí)候記錄當(dāng)前位置‘);

          }

          break;

          case MotionEvent.ACTION_UP:

          if (state != REFRESHING state != LOADING) {

          if (state == DONE) {

          // 什么都不做

          }

          if (state == PULL_To_REFRESH) {

          state = DONE;

          changeHeaderViewByState();

          Log.v(TAG, 由下拉刷新狀態(tài),到done狀態(tài));

          }

          if (state == RELEASE_To_REFRESH) {

          state = REFRESHING;

          changeHeaderViewByState();

          onRefresh();

          Log.v(TAG, 由松開刷新狀態(tài),到done狀態(tài));

          }

          }

          isRecored = false;

          isBack = false;

          break;

          case MotionEvent.ACTION_MOVE:

          int tempY = (int) event.getY();

          if (!isRecored firstItemIndex == 0) {

          Log.v(TAG, 在move時(shí)候記錄下位置);

          isRecored = true;

          startY = tempY;

          }

          if (state != REFRESHING isRecored state != LOADING) {

          // 保證在設(shè)置padding的過程中,當(dāng)前的位置一直是在head,否則如果當(dāng)列表超出屏幕的話,當(dāng)在上推的時(shí)候,列表會(huì)同時(shí)進(jìn)行滾動(dòng)

          // 可以松手去刷新了

          if (state == RELEASE_To_REFRESH) {

          setSelection(0);

          // 往上推了,推到了屏幕足夠掩蓋head的程度,但是還沒有推到全部掩蓋的地步

          if (((tempY - startY) / RATIO headContentHeight)

          (tempY - startY) > 0) {

          state = PULL_To_REFRESH;

          changeHeaderViewByState();

          Log.v(TAG, 由松開刷新狀態(tài)轉(zhuǎn)變到下拉刷新狀態(tài));

          }

          // 一下子推到頂了

          else if (tempY - startY = 0) {

          state = DONE;

          changeHeaderViewByState();

          Log.v(TAG, 由松開刷新狀態(tài)轉(zhuǎn)變到done狀態(tài));

          }

          // 往下拉了,或者還沒有上推到屏幕頂部掩蓋head的地步

          else {

          // 不用進(jìn)行特別的操作,只用更新paddingTop的值就行了

          }

          }

          // 還沒有到達(dá)顯示松開刷新的時(shí)候,DONE或者是PULL_To_REFRESH狀態(tài)

          if (state == PULL_To_REFRESH) {

          setSelection(0);

          // 下拉到可以進(jìn)入RELEASE_TO_REFRESH的狀態(tài)

          if ((tempY - startY) / RATIO >= headContentHeight) {

          state = RELEASE_To_REFRESH;

          isBack = true;

          changeHeaderViewByState();

          Log.v(TAG, 由done或者下拉刷新狀態(tài)轉(zhuǎn)變到松開刷新);

          }

          // 上推到頂了

          else if (tempY - startY = 0) {

          state = DONE;

          changeHeaderViewByState();

          Log.v(TAG, 由DOne或者下拉刷新狀態(tài)轉(zhuǎn)變到done狀態(tài));

          }

          }

          // done狀態(tài)下

          if (state == DONE) {

          if (tempY - startY > 0) {

          state = PULL_To_REFRESH;

          changeHeaderViewByState();

          }

          }

          // 更新headView的size

          if (state == PULL_To_REFRESH) {

          headView.setPadding(0, -1 * headContentHeight

          + (tempY - startY) / RATIO, 0, 0);

          }

          // 更新headView的paddingTop

          if (state == RELEASE_To_REFRESH) {

          headView.setPadding(0, (tempY - startY) / RATIO

          - headContentHeight, 0, 0);

          }

          }

          break;

          }

          }

          return super.onTouchEvent(event);

          }

          /**

          * 當(dāng)狀態(tài)改變時(shí)候,調(diào)用該方法,以更新界面

          */

          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, 當(dāng)前狀態(tài),松開刷新);

          break;

          case PULL_To_REFRESH:

          progressBar.setVisibility(View.GONE);

          tipsTextview.setVisibility(View.VISIBLE);

          lastUpdatedTextView.setVisibility(View.VISIBLE);

          arrowImageView.clearAnimation();

          arrowImageView.setVisibility(View.VISIBLE);

          // 是由RELEASE_To_REFRESH狀態(tài)轉(zhuǎn)變來的

          if (isBack) {

          isBack = false;

          arrowImageView.clearAnimation();

          arrowImageView.startAnimation(reverseAnimation);

          tipsTextview.setText(下拉刷新);

          } else {

          tipsTextview.setText(下拉刷新);

          }

          Log.v(TAG, 當(dāng)前狀態(tài),下拉刷新);

          break;

          case REFRESHING:



          關(guān)鍵詞:

          評(píng)論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();