0

my imageview not fully show on imageview width see this image its show white space https://i.stack.imgur.com/Udqmi.jpg but i want to show mageview like this shape https://i.stack.imgur.com/BlYxE.jpg and image show full in imageview no white space below is my code please help me

<ImageView
    android:id="@+id/test_button_image"
    android:layout_width="80dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="15dp"
    android:layout_height="60dp"
    android:layout_alignParentTop="true"
    android:background="@drawable/border6"
    android:src="@drawable/ic_launcher" >
</ImageView>
Pete B.
  • 3,188
  • 6
  • 25
  • 38
user2725048
  • 41
  • 1
  • 7

3 Answers3

2
android:adjustViewBounds="true"

Reference: http://developer.android.com/reference/android/widget/ImageView.html#attr_android:adjustViewBounds this should fix your problems. In this case scaling is not your problem, because image is already scaled. Problem is that container is trying to get all possible space inside layout, but image cannot expand its width because its trying to keep its ratio.

<ImageView
    android:id="@+id/test_button_image"
    android:layout_width="80dp"
    android:adjustViewBounds="true"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="15dp"
    android:layout_height="60dp"
    android:layout_alignParentTop="true"
    android:background="@drawable/border6"
    android:src="@drawable/ic_launcher" >
</ImageView>

This attribute will "crop" the remaining not used space in ImageView.

Also you should check your background image if its properly 9patch image.

I would recommend you to put the imageview without any background inside FrameLayout, and set border image for this FrameLayout.

Klawikowski
  • 605
  • 3
  • 11
0

Imageview to fill a layout (in your xml):

android:scaleType="fitXY"

If you want to cut the corners you have to :

 public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
            .getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = pixels;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}  

reference

Community
  • 1
  • 1
Dyna
  • 2,304
  • 1
  • 14
  • 25
-1
<LinearLayout
        android:layout_width="100dp"
        android:layout_height="100dp" 
        android:background="@Android:Color:white"
        android:padding="1dp" >

   <ImageView
    android:id="@+id/test_button_image"
    android:layout_width="wrapcontent"   
    android:layout_height="wrapcontent"
    android:background="@drawable/border6"
    >
</ImageView>

</LinearLayout>
Venus
  • 219
  • 1
  • 3
  • 13