Reputation: 3533
I have this FrameLayout in my LinearLayout :
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/desktopsFramelayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="none"
android:src="@drawable/accept" />
</FrameLayout>
then in code I try convert it in Drawable like this :
FrameLayout desktopFrameLayout = (FrameLayout)findViewById(R.id.desktopsFramelayout);
desktopFrameLayout.setDrawingCacheEnabled(true);
desktopFrameLayout.buildDrawingCache();
Bitmap bitmap = desktopFrameLayout.getDrawingCache();
the bitmap
is null
,why ???
Upvotes: 1
Views: 2381
Reputation: 8153
Bitmap b = null;
desktopFrameLayout.post(new Runnable() {
desktopFrameLayout.setDrawingCacheEnabled(true);
desktopFrameLayout.buildDrawingCache();
b = desktopFrameLayout.getDrawingCache();
});
Upvotes: 0
Reputation: 2373
Check out this link and read nininho's answer: Android View.getDrawingCache returns null, only null
I think this it returns null because your view has dimensions (0,0)
Upvotes: 1
Reputation: 7010
Probably because you just enabled DrawingCache but the FrameLayout didnt had any time to build it yet.
try to assign the drawingCacheEnabled in xml and call desktopFrameLayout.getDrawingCache();
Afterwards it might have the Cache build when you ask for it.
If not try it later in the lifecycle.
Upvotes: 0