Reputation: 45
I have my layout xml in this form:
<?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>
The two textviews are overlapping. The one holds an image (with transparency) and the other one, a color and a text (this is why I have them on a single RelativeLayout and overlapping). I want to get a screenshot of this RelativeLayout. I used this method but it doesn't work. Any help please?
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();
}
}
}
This method is a mixing of some codes I found ...... 09-17 16:54:12.452: W/System(4926): ClassLoader referenced unknown path: /data/app/com.sparrowred.cardsender-1/lib/arm64 09-17 16:54:12.670: W/art(4926): Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 09-17 16:54:12.796: I/System(4926): core_booster, getBoosterConfig = false 09-17 16:54:12.869: I/System(4926): core_booster, getBoosterConfig = false 09-17 16:54:13.232: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:13.246: E/HAL(4926): load: id=gralloc != hmi->id=gralloc 09-17 16:54:13.314: E/HAL(4926): load: id=gralloc != hmi->id=gralloc 09-17 16:54:13.315: I/OpenGLRenderer(4926): Initialized EGL, version 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 failed: library "/system/lib64/libhwuibp.so" not found 09-17 16:54:13.322: W/OpenGLRenderer(4926): Initialize Binary Program Cache: Load Failed 09-17 16:54:13.322: E/HAL(4926): load: id=gralloc != hmi->id=gralloc 09-17 16:54:13.456: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:17.773: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:18.189: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:20.100: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:20.195: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:20.218: I/System(4926): core_booster, getBoosterConfig = false 09-17 16:54:20.286: I/System(4926): core_booster, getBoosterConfig = false 09-17 16:54:20.635: W/Settings(4926): Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value. 09-17 16:54:20.655: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 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 is null 09-17 16:54:22.137: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:22.137: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:22.238: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:22.238: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:25.969: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:26.647: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:27.986: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:28.118: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:28.128: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:28.158: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:28.158: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:28.193: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:28.193: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:29.363: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:30.134: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:30.142: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:30.170: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:30.170: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:30.209: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:30.209: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:30.814: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:31.279: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:32.477: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:32.587: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:32.596: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:32.627: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:32.627: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:32.656: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:32.656: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:33.375: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:33.756: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:34.710: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:34.836: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:34.853: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:34.883: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:34.884: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:34.912: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:34.912: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:35.525: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:35.626: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:35.632: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:35.632: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:36.980: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:36.980: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:37.201: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:37.201: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:37.419: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:37.419: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:39.064: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:39.064: E/SpannableStringBuilder(4926): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length 09-17 16:54:39.835: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:41.707: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:45.142: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:46.084: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:47.246: I/HwSecImmHelper(4926): mSecurityInputMethodService is null 09-17 16:54:47.395: I/art(4926): System.exit called, status: 0 09-17 16:54:47.395: I/AndroidRuntime(4926): VM exiting with result code 0, cleanup skipped.
hope it's the right one
Upvotes: 0
Views: 502
Reputation: 2482
It seems you don't call buildDrawingCache
method on your layout before adding it to the bitmap by getDrawingCache
.
Do something like this (this code is without the other options you used):
RelativeLayout RTLout= (RelativeLayout )findViewById(R.id.relativeViewPrint);
RTLout.setDrawingCacheEnabled(true);
RTLout.buildDrawingCache();
Bitmap bm = view.getDrawingCache();
Upvotes: 0