Android: cómo configurar la altura / anchura de la imagen src de un ImageButton?
Android: cómo configurar la altura / ancho de la imagen (src image intead del fondo) de un ImageButton?
Quiero establecer la altura / ancho de la imagen de nivel superior (no el fondo), el tamaño de la imagen debe ser personalizado en lugar de rellenar el botón automáticamente
- Deshabilitar un ImageButton
- Cómo obtener Image Resource
- Establecer el texto en ImageButton
- Android resalta un botón de imagen cuando se hace clic
- Color de fondo en un ImageButton
- Iterate a través de ImageButtons dando enfoque a Android
- ImageButton onClick cambiar color
- Cabeza de chat Haga clic en eventos
- Imagebutton imagen completa, esquinas redondas
- Android - los estados de la superposición automática táctil / resaltado del estado de la imagen
- Android - imagen diferente para rollover en ImageButton
- ¿Cómo mostrar el texto en un ImageButton?
- Botones redondeados de la imagen del androides de las esquinas
Sólo puede utilizar el atributo ImageButton
de ImageButton
. Ajústelo en fitXY
o en fitCenter
o cualquier otra cosa según su necesidad.
Me gusta esto
<ImageButton android:id="@+id/imageButton" android:layout_width="100dp" android:layout_height="100dp" android:scaleType="fitCenter" android:src="@drawable/some_image"> </ImageButton>
Puede utilizar Bitmap.createScaledBitmap para escalar la imagen al tamaño que desee.
Bitmap image = ... //load image from your source image = Bitmap.createScaledBitmap(image, desiredHeight, desiredWidth, true);
Tuve el mismo problema … cambiar el tamaño de la imagen 'src' del botón de imagen (no el tamaño del botón sólo imagen).
lo que hice–
Moví los archivos '.png' de la carpeta 'drawable' a la carpeta 'drawable-hdpi'.
Extraño … pero funcionó.
Gracias,
Xml
<ImageButton android:id="@+id/picture_id" android:layout_width="10dp" //here width with unit. 5 dp exemple android:layout_height="3dp" //here height with unit. 3 dp exemple android:src="@drawable/picture_name" />
EDIT: (código java)
// load the origial BitMap (500 x 500 px) Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), R.drawable.android); int width = bitmapOrg.width(); int height = bitmapOrg.height(); int newWidth = 200; int newHeight = 200; // calculate the scale - in this case = 0.4f float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // create a matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // rotate the Bitmap matrix.postRotate(45); // recreate the new Bitmap Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); // make a Drawable from Bitmap to allow to set the BitMap // to the ImageView, ImageButton or what ever BitmapDrawable bmd = new BitmapDrawable(resizedBitmap); ImageView imageView = new ImageView(this); // set the Drawable on the ImageView imageView.setImageDrawable(bmd); // center the Image imageView.setScaleType(ScaleType.CENTER); // add ImageView to the Layout linLayout.addView(imageView, new LinearLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT ) );
- Declaración de actividad en AndroidManifest.xml
- ¿Cómo mostrar Toast de un Servicio después de que la actividad principal termine?