Android自定义TabHost扩展控件TabView

 @Override    public boolean onTouchEvent(MotionEvent event) {          event.setLocation(event.getX() - tabViewStart_x, event.getY());          switch (event.getAction()) {          case MotionEvent.ACTION_DOWN:              // 获取选中Tab.               currentTab = getCurrentTab(event, false);              if (currentTab != null) {                  longPress = true;                  // 长按事件.                   onLongPress();                  currentTabStart_x = currentTab.getRegion().left;                  currentTabMove_x = 0;                  setTabFocus(currentTab);              }              x = (int) event.getX();              y = (int) event.getY();              break;          case MotionEvent.ACTION_MOVE:              if (Math.abs(event.getX() - x) > 10 || Math.abs(event.getY() - y) >10) {                  longPress = false;              }              if (currentTab == null) {                  break;              }              if (scrollTab) {                  Tab tab = getCurrentTab(event, true);                  // 长按Tab移动,实现Tab之间的替换.                   if (tab != null && currentTab != tab) {                      int tabID = tabs.indexOf(tab);                      int currentTabID = tabs.indexOf(currentTab);                      tabs.set(tabID, currentTab);                      tabs.set(currentTabID, tab);                      initTabRegion();                  }              } else {                  // 整个View的拖拽.                   tabViewStart_x += (int) event.getX() - x;              }              currentTabMove_x = (int) event.getX() - x;              break;          case MotionEvent.ACTION_UP:              longPress = false;              scrollTab = false;              if (task != null) {                  task.cancel();              }              // 拖拽松开时开启一个Timer,实现自定义动画效果.               task = new TimerTask() {                  @Override                  public void run() {                      animateHandler.sendEmptyMessage(1);                  }              };              if (tabViewStart_x > 0) {                  start = 0;                  timer.schedule(task, 020);              }              break;          }          event.setLocation(event.getX() + tabViewStart_x, event.getY());          invalidate();          return true;      }  

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

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