截圖我有我的佈局XML格式如下:採取嵌套的RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/
res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#3fb399"
tools:context="com.sparrowred.cardsender.customizeCard">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/
res/android"
android:id="@+id/relativeViewPrint"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:weightSum="1"
android:layout_above="@+id/button_send"
android:layout_alignParentStart="true"
android:layout_below="@+id/add_button">
<TextView
android:layout_width="match_parent"
android:layout_height="180dp"
android:id="@+id/textView_wish_card"
android:textAlignment="center"
android:textSize="20sp"
android:layout_weight="0.06"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="149dp"
android:layout_height="112dp"
android:background="@drawable/image0"
android:layout_gravity="center"
android:alpha="0.4"
android:id="@+id/textView_wish_cardBack"
android:layout_weight="0.75"
android:layout_alignTop="@+id/textView_wish_card"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
兩個textviews重疊。一個擁有一個圖像(具有透明度),另一個擁有一個顏色和一個文本(這就是爲什麼我將它們放在一個RelativeLayout上並重疊)。我想獲得這個RelativeLayout的截圖。我用這種方法,但它不起作用。請幫忙嗎?
private void ScreenShot2(){
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
RTLout.measure(View.MeasureSpec.makeMeasureSpec(0,
size.x), View.MeasureSpec.makeMeasureSpec(0, size.y));
RTLout.layout(0, 0, RTLout.getWidth(), RTLout.getHeight());
RTLout.setDrawingCacheEnabled(true);
RTLout.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
Bitmap b = Bitmap.createBitmap(RTLout.getDrawingCache());
RTLout.setDrawingCacheEnabled(false);
if(b !=null) {
try {
String extr = Environment.getExternalStorageDirectory().
getAbsolutePath().toString() + File.separator + "Pictures"
+ File.separator + "Screenshots";
File dir = new File(extr);
if (!dir.exists())
dir.mkdirs();
String fileName =
new SimpleDateFormat("yyyyMMddhhmm'_report.jpg'").
format(new Date());
File myPath = new File(dir, fileName);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(getContentResolver(),
b, "Screen", "screen");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}catch (Exception e) {
e.printStackTrace();
}
}
}
此方法的一些代碼我發現了一個混合...... 09-17 16:54:12.452:W /系統(4926):類加載器中引用了未知的路徑:/數據/應用程序/ com.sparrowred.cardsender-1/lib/arm64 09-17 16:54:12.670:W/art(4926):Android 4.1之前,方法android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter( android.graphics.PorterDuffColorFilter,android.content.res.ColorStateList,android.graphics.PorterDuff $ Mode)將不正確地覆蓋android.graphics.drawable.Drawable中的包私有方法 09-17 16:54:12.796:I/System(4926):core_booster,getBoosterConfig = false 09-17 16:54:12.869:I/Sys (4926):core_booster,getBoosterConfig = false 09-17 16:54:13.232:I/HwSecImmHelper(4926):mSecurityInputMethodService爲null 09-17 16:54:13.246:E/HAL(4926):load:id = gralloc!= hmi-> id = gralloc 09-17 16:54:13.315:E/HAL(4926):load:id = gralloc!= hmi-> id = gralloc 09-17 16:54:13.315: I/OpenGLRenderer(4926):初始化EGL,版本1.4 09-17 16:54:13.322:W/OpenGLRenderer(4926):load:so =/system/lib64/libhwuibp.so 09-17 16:54:13.322 :W/OpenGLRenderer(4926):dlopen失敗:庫「/system/lib64/libhwuibp.so」找不到 09-17 16:54:13.322:W/OpenGLRenderer(4926):初始化二進制程序高速緩存:加載失敗 09 -17 16:54:13.322:E/HAL(4926):load:id = gralloc!= hmi-> id = gralloc 09-17 16:54:13.456:I/HwSec ImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:17.773:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:18.189:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09 -17 16:54:20.100:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:20.195:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:20.218:I/(4926):core_booster,getBoosterConfig = false 09-17 16: airplane_mode_on已從android.provider.Settings.System移至android.provider.Settings.Global,並返回只讀值。 09-17 16:54:20.655:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:20.842:I/System(4926):core_booster,getBoosterConfig = false 09-17 16:54: 20.906:I/System(4926):core_booster,getBoosterConfig = false 09-17 16:54:21.452:I/HwSecImmHelper(4926):mSecurityInputMethodService爲null 09-17 16:54:22.137:I/HwSecImmHelper(4926) :mSecurityInputMethodService爲空 09-17 16:54:22.137:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:22.238:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能爲零長度 09 -17 16:54:22.238:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能爲零長度 09-17 16:54:25.969:I/Hw SecImmHelper(4926):mSecurityInputMethodService爲null 09-17 16:54:26.647:I/HwSecImmHelper(4926):mSecurityInputMethodService爲null 09-17 16:54:27.986:I/HwSecImmHelper(4926):mSecurityInputMethodService爲null 09 -17 16:54:28。118:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:28.128:I/HwSecImmHelper(4926):mSecurityInputMethodService爲null 09-17 16:54:28.158:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:28.158:I/HwSecImmHelper(4926):mSecurityInputMethodService爲null 09-17 16:54:28.193:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有一個零長度 09-17 16:54:28.193:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能爲零長度 09-17 16:54:29.363:I/HwSecImmHelper(4926):mSecurityInputMethodService爲null 09-17 16:54:30.134: I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:30.142:I/HwSecImmHelper(4926):mSecurityInputMet hodService爲空 09-17 16:54:30.170:I/HwSecImmHelper(4926):mSecurityInputMethodService爲null 09-17 16:54:30.170:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54 :30.209:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能具有零長度 09-17 16:54:30.209:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能具有零長度 09-17 16:54:30.814 :I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:31.279:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:32.477:I/HwSecImmHelper(4926):mSecurityInputMethodService is null 09-17 16:54:32.587:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:32.596:I/HwSecImmHelper(4926):mSecurityInputMethodService爲null 09-17 16:54:32.627:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:32.627: (4926):mSecurityInputMethodService爲空 09-17 16:54:32.656:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能爲零長度 09-17 16:54:32.656:E/SpannableStringBuilder(4926) :SPAN_EXCLUSIVE_EXCLUSIVE跨度不能爲零長度 09-17 16:54:33.375:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:33.756:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09 -17 16:54:34.710:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:34.836:I/HwSecImmHelper(4926 ):mSecurityInputMethodService爲空 09-17 16:54:34.853:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:34.883:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16 :54:34.884:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:34.912:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能爲零長度 09-17 16:54:34.912:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能爲零長度 09-17 16:54:35.525:I/HwSecImmHelper(4926):mSecurityInputMethodService爲null 09-17 16:54:35.626:I/HwSecImmHelper(4926) mSecurityInputMethodService爲空 09-17 16:54:35.632:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度Cann不具有零長度 09-17 16:54:35.632:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能具有零長度 09-17 16:54:36.980:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能具有零長度 09-17 16:54:36.980:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有零長度 09-17 16:54:37.201:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能有零長度 09-17 16:54:37.201:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能爲零長度 09-17 16:54:37.419:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能具有零長度 09-17 16:54:37。419:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能具有零長度 09-17 16:54:39.064:E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能具有零長度 09-17 16:54:39.064: E/SpannableStringBuilder(4926):SPAN_EXCLUSIVE_EXCLUSIVE跨度不能爲零長度 09-17 16:54:39.835:I/HwSecImmHelper(4926):mSecurityInputMethodService爲null 09-17 16:54:41.707:I/HwSecImmHelper(4926) :mSecurityInputMethodService爲空 09-17 16:54:45.142:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:46.084:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16: 54:47.246:I/HwSecImmHelper(4926):mSecurityInputMethodService爲空 09-17 16:54:47.395:I/art(4926) System.exit調用,狀態:0 09-17 16:54:47.395:I/AndroidRuntime(4926):VM退出,結果代碼爲0,清除跳過。
希望這是正確的
謝謝,但它並沒有對我的工作。 –
在這個過程中你有沒有遇到任何異常,或者只是簡單地保存一個空文件? – abbath
我只得到這個信息:I/HwSecImmHelper:mSecurityInputMethodService爲空 這是我第一次嘗試通過android編程....:/ –