2013-03-05 4 views
1

Je cette FrameLayout dans mon LinearLayout:FrameLayout android Convertir étirables

<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> 

puis dans le code j'essaie de convertir en Drawable comme ceci:

FrameLayout desktopFrameLayout = (FrameLayout)findViewById(R.id.desktopsFramelayout); 

     desktopFrameLayout.setDrawingCacheEnabled(true); 
     desktopFrameLayout.buildDrawingCache();  
     Bitmap bitmap = desktopFrameLayout.getDrawingCache(); 

le bitmap est null, pourquoi ?? ?

Répondre

0

Probablement parce que vous venez d'activer DrawingCache mais que FrameLayout n'a pas eu le temps de le construire pour le moment. Essayez d'assigner le drawingCacheEnabled dans xml et appelez desktopFrameLayout.getDrawingCache(); Par la suite, il se peut que le cache soit construit lorsque vous le demanderez.

Si non l'essayer plus tard dans le cycle de vie.

0
Bitmap b = null; 
desktopFrameLayout.post(new Runnable() { 
    desktopFrameLayout.setDrawingCacheEnabled(true); 
    desktopFrameLayout.buildDrawingCache();  
    b = desktopFrameLayout.getDrawingCache(); 
});