Cómo convertir linearlayout a imagen
Quiero convertir el layout
completo con su contenido ( views
) en la imagen de Drawable?
- Android 3-level-ExpandableListView no mostrar filas sólo en el tercer nivel
- Cómo deshabilitar el colapso de un ExpandableListView?
- ExpandableListView muestra de Google
- Android toggleButton.setOnText y .invalidate no actualiza el texto
- Refresh ExpandableListView al agregar datos: keep state
- Manejo de la rotación de la pantalla en WebView
- Android Studio 2.2.0.12 diseñador automáticamente anuncios "@ + id" prefijo antes de la identificación de la vista y que causa este error inusual
- El fondo de la vista ampliable se vuelve negro cuando se amplía
- Widgets de Android: Cómo agregar vistas a RemoteViews en tiempo de ejecución
- Cargar HTML estático en Webview
- Pasar de una actividad a otra
- alerta en la vista web incorporada
- Surface - dequeueBuffer failed (Error desconocido 2147483646)
Pruebe el siguiente código:
public class AndroidWebImage extends Activity { ImageView bmImage; LinearLayout view; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); view = (LinearLayout)findViewById(R.id.screen); bmImage = (ImageView)findViewById(R.id.image); view.setDrawingCacheEnabled(true); // this is the important code :) // Without it the view will have a dimension of 0,0 and the bitmap will be null view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.buildDrawingCache(true); Bitmap b = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); // clear drawing cache bmImage.setImageBitmap(b); }; }
Echa un vistazo, tienes que usar:
view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
He utilizado el siguiente main.xml :
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/screen" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <ImageView android:id="@+id/image" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>
El resultado es:
Referencia
- Android, ¿cómo determinar si se produjo un reinicio?
- Cambiar la ubicación del SDK en Android Studio: espacios en blanco en la ubicación del directorio