編輯:關於android開發
protected void onDraw(Canvas canvas) public void buildDrawingCache() public void destroyDrawingCache() public Bitmap getDrawingCache() public void setDrawingCacheEnabled(boolean enabled)
下面是常見的幾個View截屏的示例: 1.View轉Bitmap
public final Bitmap screenShot(View view) { if (null == view) { throw new IllegalArgumentException("parameter can't be null."); } view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bitmap = view.getDrawingCache(); return bitmap; }
2. Activity轉Bitmap,不帶狀態欄
public final Bitmap screenShot(Activity activity) { if (null == activity) { throw new IllegalArgumentException("parameter can't be null."); } View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap b1 = view.getDrawingCache(); Rect frame = new Rect(); view.getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; Point point = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(point); int width = point.x; int height = point.y; Bitmap b2 = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight); view.destroyDrawingCache(); return b2; }
3. ScrollView轉長Bitmap(類似錘子便簽的截長圖)
public final Bitmap screenShot(ScrollView scrollView) { if (null == scrollView) { throw new IllegalArgumentException("parameter can't be null."); } int height = 0; Bitmap bitmap; for (int i = 0, s = scrollView.getChildCount(); i < s; i++) { height += scrollView.getChildAt(i).getHeight(); scrollView.getChildAt(i).setBackgroundResource(android.R.drawable.screen_background_light); } bitmap = Bitmap.createBitmap(scrollView.getWidth(), height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); scrollView.draw(canvas); return bitmap; }
谷歌電子市場3--應用,谷歌電子市場3-- public class AppFragment extends BaseFragment { Arr
Android4.4訪問外部存儲,android4.4訪問存儲 在Android 4.4系統中,外置存儲卡(SD卡)被稱為二級外部存儲設備(secondary
VS 2015 update2 裝xamarin後,編輯axml文件無智能提示的解決方法。,xamarinaxml1、從github網上下載xsd文件。地址:https:
Android的動畫類型 Android的animation由四種類型組成 Android動畫模式 Animation主要有兩種動畫模式: 一種是tweene