Java Code Examples for android.widget.ScrollView#getChildCount()
The following examples show how to use
android.widget.ScrollView#getChildCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewShot.java From zone-sdk with MIT License | 6 votes |
/** * 截取scrollview的屏幕 **/ public static Bitmap getBitmapByScrollView(ScrollView scrollView) { int h = 0; Bitmap bitmap = null; // 获取listView实际高度 for (int i = 0; i < scrollView.getChildCount(); i++) h += scrollView.getChildAt(i).getHeight(); 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); return bitmap; }
Example 2
Source File: PtrDefaultHandler2.java From android-Ultra-Pull-To-Refresh-With-Load-More-master with MIT License | 6 votes |
public static boolean canChildScrollDown(View view) { if (android.os.Build.VERSION.SDK_INT < 14) { if (view instanceof AbsListView) { final AbsListView absListView = (AbsListView) view; return absListView.getChildCount() > 0 && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom()); } else if (view instanceof ScrollView) { ScrollView scrollView = (ScrollView) view; if (scrollView.getChildCount() == 0) { return false; } else { return scrollView.getScrollY() < scrollView.getChildAt(0).getHeight() - scrollView.getHeight(); } } else { return false; } } else { return view.canScrollVertically(1); } }
Example 3
Source File: ConvertToBitmapUtil.java From AndroidStudyDemo with GNU General Public License v2.0 | 6 votes |
/** * 将ScrollView转换为Bitmap * @param scrollView * @return */ public static Bitmap convertScrollViewToBitmap(ScrollView scrollView) { int h = 0; Bitmap bitmap = null; // 获取scrollview实际高度 for (int i = 0; i < scrollView.getChildCount(); i++) { h += scrollView.getChildAt(i).getHeight(); scrollView.getChildAt(i).setBackgroundColor( Color.parseColor("#ffffff")); } // 创建对应大小的bitmap bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.RGB_565); final Canvas canvas = new Canvas(bitmap); scrollView.draw(canvas); return bitmap; }
Example 4
Source File: SlideBottomPanel.java From pius1 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Copy From ScrollView (API Level >= 14) * <p>The scroll range of a scroll view is the overall height of all of its * children.</p> */ 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; }
Example 5
Source File: PtrDefaultHandler2.java From Elephant with Apache License 2.0 | 6 votes |
public static boolean canChildScrollDown(View view) { if (android.os.Build.VERSION.SDK_INT < 14) { if (view instanceof AbsListView) { final AbsListView absListView = (AbsListView) view; return absListView.getChildCount() > 0 && (absListView.getLastVisiblePosition() < absListView.getChildCount() - 1 || absListView.getChildAt(absListView.getChildCount() - 1).getBottom() > absListView.getPaddingBottom()); } else if (view instanceof ScrollView) { ScrollView scrollView = (ScrollView) view; if (scrollView.getChildCount() == 0) { return false; } else { return scrollView.getScrollY() < scrollView.getChildAt(0).getHeight() - scrollView.getHeight(); } } else { return false; } } else { return view.canScrollVertically(1); } }
Example 6
Source File: LongImageUtils.java From SuperNote with GNU General Public License v3.0 | 6 votes |
/** * 截取scrollview的屏幕 **/ public static Bitmap getScrollViewBitmap(ScrollView scrollView) { int h = 0; Bitmap bitmap; for (int i = 0; i < scrollView.getChildCount(); i++) { h += scrollView.getChildAt(i).getHeight(); } // 创建对应大小的bitmap bitmap = Bitmap.createBitmap(ScreenUtils.getScreenWidth(), h, Bitmap.Config.ARGB_4444); final Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.parseColor("#f2f7fa")); scrollView.draw(canvas); return bitmap; }
Example 7
Source File: SaveBitmapUtil.java From OneText_For_Android with GNU Lesser General Public License v3.0 | 5 votes |
/** * 对ScrollView进行截图 * * @param scrollView * @return */ public static Bitmap shotScrollView(ScrollView scrollView) { int h = 0; Bitmap bitmap = null; for (int i = 0; i < scrollView.getChildCount(); i++) { h += scrollView.getChildAt(i).getHeight(); scrollView.getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff")); } bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.RGB_565); final Canvas canvas = new Canvas(bitmap); scrollView.draw(canvas); return bitmap; }
Example 8
Source File: ParallaxViewController.java From Carpaccio with Apache License 2.0 | 5 votes |
public void registerParallax(ScrollView view, boolean replaceWithObservableScrollView) { if (replaceWithObservableScrollView && !(view instanceof ObservableScrollView)) { CommonViewController replaceViewController = new CommonViewController(); ObservableScrollView newView = replaceViewController.replaceViewithTagToRemove(view, "com.github.ksoichiro.android.observablescrollview.ObservableScrollView", "registerParallax()"); if (view.getChildCount() > 0) { View scrollViewChild = view.getChildAt(0); view.removeView(scrollViewChild); newView.addView(scrollViewChild); } view = newView; } if (view != null) ((ObservableScrollView) view).setScrollViewCallbacks(new ObservableScrollViewCallbacks() { @Override public void onScrollChanged(int i, boolean b, boolean b1) { scrolled(i); } @Override public void onDownMotionEvent() { } @Override public void onUpOrCancelMotionEvent(ScrollState scrollState) { } }); }
Example 9
Source File: NoteEditActivity.java From nono-android with GNU General Public License v3.0 | 5 votes |
@Override protected void handleIniCursor() { super.handleIniCursor(); noteEditTitle.setText(Title); editTextWrapper.forceRefocus(); if(content!=null){ editTextWrapper.setHtml(content); } RichEdit richEdit = null; ViewGroup realEditor =(ViewGroup) editTextWrapper.getChildAt(0); int wrapperChildNum = realEditor.getChildCount(); for(int i = 0;i<wrapperChildNum;i++){ View v = realEditor.getChildAt(i); if(v instanceof ScrollView){ ScrollView editWrapper = (ScrollView)v; int editChildIndex = editWrapper.getChildCount(); for(int childIndex = 0;childIndex <editChildIndex;childIndex++){ if(editWrapper.getChildAt(childIndex ) instanceof RichEdit){ richEdit = (RichEdit)editWrapper.getChildAt(childIndex ); } } } } if(viewIndex>-1){ View richTxt = richEdit.getChildAt(viewIndex); richTxt.requestFocus(); if(sel>-1 && richTxt instanceof RichEditText){ ((RichEditText)richTxt).editText.setSelection(sel); } } }
Example 10
Source File: ScreenUtils.java From BaseProject with Apache License 2.0 | 5 votes |
/** * 截取scrollview的屏幕 * **/ public static Bitmap getScrollViewBitmap(ScrollView scrollView) { int h = 0; Bitmap bitmap; for (int i = 0; i < scrollView.getChildCount(); i++) { h += scrollView.getChildAt(i).getHeight(); } // 创建对应大小的bitmap bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); scrollView.draw(canvas); return bitmap; }
Example 11
Source File: AppUtils.java From YCWebView with Apache License 2.0 | 5 votes |
/** * 截取scrollview的屏幕 * @param scrollView * @return */ 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).setBackgroundColor(Color.WHITE); } // 创建对应大小的bitmap bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); scrollView.draw(canvas); return bitmap; }
Example 12
Source File: ShareUtil.java From Huochexing12306 with Apache License 2.0 | 5 votes |
/** * 截取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(); } // 创建对应大小的bitmap bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); scrollView.draw(canvas); return bitmap; }
Example 13
Source File: RxImage.java From FakeWeather with Apache License 2.0 | 5 votes |
private static Bitmap saveScrollViewToBitmap(ScrollView scrollView) { int h = 0; for (int i = 0; i < scrollView.getChildCount(); i++) { h += scrollView.getChildAt(i).getHeight(); } Bitmap bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); scrollView.draw(canvas); return bitmap; }
Example 14
Source File: ScreenUtils.java From Tok-Android with GNU General Public License v3.0 | 5 votes |
public static Bitmap shotScrollView(ScrollView scrollView) { int h = 0; Bitmap bitmap = null; for (int i = 0; i < scrollView.getChildCount(); i++) { h += scrollView.getChildAt(i).getHeight(); scrollView.getChildAt(i).setBackgroundColor(Color.parseColor("#ffffff")); } bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, Bitmap.Config.RGB_565); final Canvas canvas = new Canvas(bitmap); scrollView.draw(canvas); return bitmap; }
Example 15
Source File: MDRootLayout.java From talk-android with MIT License | 4 votes |
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; }
Example 16
Source File: ConvertUtils.java From AndroidDownload with Apache License 2.0 | 4 votes |
/** * 把view转化为bitmap(截图) * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html */ public static Bitmap toBitmap(View view) { int width = view.getWidth(); int height = view.getHeight(); if (view instanceof ListView) { height = 0; // 获取listView实际高度 ListView listView = (ListView) view; for (int i = 0; i < listView.getChildCount(); i++) { height += listView.getChildAt(i).getHeight(); } } else if (view instanceof ScrollView) { height = 0; // 获取scrollView实际高度 ScrollView scrollView = (ScrollView) view; for (int i = 0; i < scrollView.getChildCount(); i++) { height += scrollView.getChildAt(i).getHeight(); } } view.setDrawingCacheEnabled(true); view.clearFocus(); view.setPressed(false); boolean willNotCache = view.willNotCacheDrawing(); view.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent for the duration of this operation int color = view.getDrawingCacheBackgroundColor(); view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素) if (color != Color.WHITE) { view.destroyDrawingCache(); } view.buildDrawingCache(); Bitmap cacheBitmap = view.getDrawingCache(); if (cacheBitmap == null) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(cacheBitmap, 0, 0, null); canvas.save(Canvas.ALL_SAVE_FLAG); canvas.restore(); if (!bitmap.isRecycled()) { LogUtils.verbose("recycle bitmap: " + bitmap.toString()); bitmap.recycle(); } // Restore the view view.destroyDrawingCache(); view.setWillNotCacheDrawing(willNotCache); view.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 17
Source File: ConvertUtils.java From MyBookshelf with GNU General Public License v3.0 | 4 votes |
/** * 把view转化为bitmap(截图) * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html */ public static Bitmap toBitmap(View view) { int width = view.getWidth(); int height = view.getHeight(); if (view instanceof ListView) { height = 0; // 获取listView实际高度 ListView listView = (ListView) view; for (int i = 0; i < listView.getChildCount(); i++) { height += listView.getChildAt(i).getHeight(); } } else if (view instanceof ScrollView) { height = 0; // 获取scrollView实际高度 ScrollView scrollView = (ScrollView) view; for (int i = 0; i < scrollView.getChildCount(); i++) { height += scrollView.getChildAt(i).getHeight(); } } view.setDrawingCacheEnabled(true); view.clearFocus(); view.setPressed(false); boolean willNotCache = view.willNotCacheDrawing(); view.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent for the duration of this operation int color = view.getDrawingCacheBackgroundColor(); view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素) if (color != Color.WHITE) { view.destroyDrawingCache(); } view.buildDrawingCache(); Bitmap cacheBitmap = view.getDrawingCache(); if (cacheBitmap == null) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(cacheBitmap, 0, 0, null); canvas.save(); canvas.restore(); if (!bitmap.isRecycled()) { bitmap.recycle(); } // Restore the view view.destroyDrawingCache(); view.setWillNotCacheDrawing(willNotCache); view.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 18
Source File: ConvertUtils.java From FilePicker with MIT License | 4 votes |
/** * 把view转化为bitmap(截图) * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html */ public static Bitmap toBitmap(View view) { int width = view.getWidth(); int height = view.getHeight(); if (view instanceof ListView) { height = 0; // 获取listView实际高度 ListView listView = (ListView) view; for (int i = 0; i < listView.getChildCount(); i++) { height += listView.getChildAt(i).getHeight(); } } else if (view instanceof ScrollView) { height = 0; // 获取scrollView实际高度 ScrollView scrollView = (ScrollView) view; for (int i = 0; i < scrollView.getChildCount(); i++) { height += scrollView.getChildAt(i).getHeight(); } } view.setDrawingCacheEnabled(true); view.clearFocus(); view.setPressed(false); boolean willNotCache = view.willNotCacheDrawing(); view.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent for the duration of this operation int color = view.getDrawingCacheBackgroundColor(); view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素) if (color != Color.WHITE) { view.destroyDrawingCache(); } view.buildDrawingCache(); Bitmap cacheBitmap = view.getDrawingCache(); if (cacheBitmap == null) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(cacheBitmap, 0, 0, null); canvas.save(Canvas.ALL_SAVE_FLAG); canvas.restore(); if (!bitmap.isRecycled()) { LogUtils.verbose("recycle bitmap: " + bitmap.toString()); bitmap.recycle(); } // Restore the view view.destroyDrawingCache(); view.setWillNotCacheDrawing(willNotCache); view.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 19
Source File: ConvertUtils.java From a with GNU General Public License v3.0 | 4 votes |
/** * 把view转化为bitmap(截图) * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html */ public static Bitmap toBitmap(View view) { int width = view.getWidth(); int height = view.getHeight(); if (view instanceof ListView) { height = 0; // 获取listView实际高度 ListView listView = (ListView) view; for (int i = 0; i < listView.getChildCount(); i++) { height += listView.getChildAt(i).getHeight(); } } else if (view instanceof ScrollView) { height = 0; // 获取scrollView实际高度 ScrollView scrollView = (ScrollView) view; for (int i = 0; i < scrollView.getChildCount(); i++) { height += scrollView.getChildAt(i).getHeight(); } } view.setDrawingCacheEnabled(true); view.clearFocus(); view.setPressed(false); boolean willNotCache = view.willNotCacheDrawing(); view.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent for the duration of this operation int color = view.getDrawingCacheBackgroundColor(); view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素) if (color != Color.WHITE) { view.destroyDrawingCache(); } view.buildDrawingCache(); Bitmap cacheBitmap = view.getDrawingCache(); if (cacheBitmap == null) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(cacheBitmap, 0, 0, null); canvas.save(); canvas.restore(); if (!bitmap.isRecycled()) { bitmap.recycle(); } // Restore the view view.destroyDrawingCache(); view.setWillNotCacheDrawing(willNotCache); view.setDrawingCacheBackgroundColor(color); return bitmap; }
Example 20
Source File: ConvertUtils.java From AndroidPicker with MIT License | 4 votes |
/** * 把view转化为bitmap(截图) * 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html */ public static Bitmap toBitmap(View view) { int width = view.getWidth(); int height = view.getHeight(); if (view instanceof ListView) { height = 0; // 获取listView实际高度 ListView listView = (ListView) view; for (int i = 0; i < listView.getChildCount(); i++) { height += listView.getChildAt(i).getHeight(); } } else if (view instanceof ScrollView) { height = 0; // 获取scrollView实际高度 ScrollView scrollView = (ScrollView) view; for (int i = 0; i < scrollView.getChildCount(); i++) { height += scrollView.getChildAt(i).getHeight(); } } view.setDrawingCacheEnabled(true); view.clearFocus(); view.setPressed(false); boolean willNotCache = view.willNotCacheDrawing(); view.setWillNotCacheDrawing(false); // Reset the drawing cache background color to fully transparent for the duration of this operation int color = view.getDrawingCacheBackgroundColor(); view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素) if (color != Color.WHITE) { view.destroyDrawingCache(); } view.buildDrawingCache(); Bitmap cacheBitmap = view.getDrawingCache(); if (cacheBitmap == null) { return null; } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(cacheBitmap, 0, 0, null); canvas.save(); canvas.restore(); if (!bitmap.isRecycled()) { LogUtils.verbose("recycle bitmap: " + bitmap.toString()); bitmap.recycle(); } // Restore the view view.destroyDrawingCache(); view.setWillNotCacheDrawing(willNotCache); view.setDrawingCacheBackgroundColor(color); return bitmap; }