Esempio n. 1
0
 /** 截取scrollview的屏幕 * */
 public static Bitmap getBitmapByView(ScrollView scrollView) {
   int h = 0;
   Bitmap bitmap = null;
   // 获取listView实际高度
   for (int i = 0; i < scrollView.getChildCount(); i++) {
     h += scrollView.getChildAt(i).getHeight();
     //            scrollView.getChildAt(i).setBackgroundResource(R.drawable.bg3);
   }
   Log.d(TAG, "实际高度:" + h);
   Log.d(TAG, " 高度:" + scrollView.getHeight());
   // 创建对应大小的bitmap
   bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.ARGB_8888);
   final Canvas canvas = new Canvas(bitmap);
   scrollView.draw(canvas);
   // 测试输出
   FileOutputStream out = null;
   try {
     out = new FileOutputStream("/sdcard/screen_test.png");
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   }
   try {
     if (null != out) {
       bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
       out.flush();
       out.close();
     }
   } catch (IOException e) {
     // TODO: handle exception
   }
   return bitmap;
 }
 @Override
 public void run() {
   int off = mLayout.getMeasuredHeight() - sView.getHeight();
   if (off > 0) {
     sView.scrollTo(0, off); // 改变滚动条的位置
   }
 }
  public void animateSubjectOut(final SubjectCard materia) {
    final List<View> toBeAnimated = new ArrayList<View>();
    boolean after = false;
    for (SubjectCard mtr : mSubjectCards) {
      if (after) toBeAnimated.add(mtr);
      if (mtr == materia) after = true;
    }
    toBeAnimated.add(mAddButton);
    final int numberToBeAnimated = toBeAnimated.size();

    int maxScroll = mScrollView.getChildAt(0).getHeight() - mScrollView.getHeight(),
        materiaHeight = materia.getHeight();
    final int initScroll = mScrollView.getScrollY(),
        scrollBy =
            ((maxScroll < initScroll + materiaHeight)
                    ? Math.max(maxScroll - materiaHeight, 0)
                    : initScroll)
                - initScroll;
    ValueAnimator listAnimator = ValueAnimator.ofFloat(0, -materiaHeight);
    listAnimator.setInterpolator(new DecelerateInterpolator(3.2f));
    listAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            for (int i = 0; i < numberToBeAnimated; i++)
              ViewHelper.setTranslationY(toBeAnimated.get(i), value);
            ViewHelper.setScrollY(
                mScrollView, (int) (initScroll + scrollBy * animation.getAnimatedFraction()));
          }
        });
    listAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            mSubjectCards.remove(materia);
            mSubjectsLayout.removeView(materia);
            mSqlHelper.remove(materia.getData().getSqlID());
            updateTotal();
            mScrollView.setVerticalScrollBarEnabled(true);
            mScrollView.setOnTouchListener(null);
            for (View mtr : toBeAnimated) ViewHelper.setTranslationY(mtr, 0);
          }
        });
    listAnimator.setDuration(700);
    mScrollView.setVerticalScrollBarEnabled(false);
    mScrollView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        }); // disable user scrolling during the animation

    if (ViewHelper.getTranslationX(materia) == 0) materia.swipeRight(0, 0);
    listAnimator.setStartDelay(500);
    listAnimator.start();
  }
Esempio n. 4
0
 /**
  * Copy From ScrollView (API Level >= 14)
  *
  * @param direction Negative to check scrolling up, positive to check scrolling down.
  * @return true if the scrollView can be scrolled in the specified direction, false otherwise
  */
 private boolean scrollViewCanScrollVertically(ScrollView scrollView, int direction) {
   final int offset = Math.max(0, scrollView.getScrollY());
   final int range = computeVerticalScrollRange(scrollView) - scrollView.getHeight();
   if (range == 0) return false;
   if (direction < 0) { // scroll up
     return offset > 0;
   } else { // scroll down
     return offset < range - 1;
   }
 }
Esempio n. 5
0
 @MediumTest
 public void testPreconditions() {
   assertTrue(
       "top text should be larger than screen", mTopText.getHeight() > mScrollView.getHeight());
   assertTrue(
       "scroll view should have focus (because nothing else focusable "
           + "is on screen), but "
           + getActivity().getScrollView().findFocus()
           + " does instead",
       getActivity().getScrollView().isFocused());
 }
  public boolean isViewBeingDragged(MotionEvent event, ScrollView view) {
    if (view.getChildCount() == 0) {
      return true;
    }

    view.getLocationOnScreen(mViewLocationResult);
    final int viewLeft = mViewLocationResult[0], viewTop = mViewLocationResult[1];
    mRect.set(viewLeft, viewTop, viewLeft + view.getWidth(), viewTop + view.getHeight());
    final int rawX = (int) event.getRawX(), rawY = (int) event.getRawY();
    if (mRect.contains(rawX, rawY)) {
      return isReadyForPull(view, rawX - mRect.left, rawY - mRect.top);
    }

    return false;
  }
Esempio n. 7
0
  /**
   * Copy From ScrollView (API Level >= 14)
   *
   * <p>The scroll range of a scroll view is the overall height of all of its children.
   */
  private int computeVerticalScrollRange(ScrollView scrollView) {
    final int count = scrollView.getChildCount();
    final int contentHeight =
        scrollView.getHeight() - scrollView.getPaddingBottom() - scrollView.getPaddingTop();
    if (count == 0) {
      return contentHeight;
    }

    int scrollRange = scrollView.getChildAt(0).getBottom();
    final int scrollY = scrollView.getScrollY();
    final int overscrollBottom = Math.max(0, scrollRange - contentHeight);
    if (scrollY < 0) {
      scrollRange -= scrollY;
    } else if (scrollY > overscrollBottom) {
      scrollRange += scrollY - overscrollBottom;
    }

    return scrollRange;
  }
  private void setNextSelectedPositionInt(int position) {
    if (mContentScrollView.getHeight() == 0) {
      setSelection(position);
      return;
    }

    mSelectedPosition = position;

    initItemViewsScrollYArr();
    mContentScrollView.scrollTo(
        mContentScrollView.getScrollX(), mItemViewsScrollYArr[mSelectedPosition]);
    if (mOnItemSelectedListener != null) {
      mOnItemSelectedListener.onItemSelected(
          this,
          mCachedSubViewList.get(mSelectedPosition),
          mSelectedPosition,
          mAdapter.getItemId(mSelectedPosition));
    }
  }
 /**
  * Sets the currently selected item.
  *
  * @param position
  */
 public void setSelection(final int position) {
   if (mAdapter == null || mAdapter.getCount() < 1) {
     throw new NullPointerException("Currently no items!");
   }
   if (position < 0 || position >= mAdapter.getCount()) {
     throw new IllegalArgumentException("Position out of index");
   }
   if (mContentScrollView.getHeight() == 0) {
     mContentScrollView.postDelayed(
         new Runnable() {
           @Override
           public void run() {
             setNextSelectedPositionInt(position);
           }
         },
         1);
   } else {
     setNextSelectedPositionInt(position);
   }
 }