Exemplo 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;
 }
  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;
  }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
0
 private static boolean canScrollViewScroll(ScrollView sv) {
   if (sv.getChildCount() == 0) return false;
   final int childHeight = sv.getChildAt(0).getMeasuredHeight();
   return sv.getMeasuredHeight() - sv.getPaddingTop() - sv.getPaddingBottom() < childHeight;
 }