I have a cell with a fixed width and height, let it be 100x100px. Inside that cell I want to display an ImageView
with a border around.
My first idea was to put
This is what worked for me:
<ImageView
android:id="@+id/dialpad_phone_country_flag"
android:layout_width="22dp"
android:layout_height="15dp"
android:scaleType="fitXY"
android:background="@color/gen_black"
android:padding="1px"/>
Just add the property adjustViewBounds to the ImageView.
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/image_border"
android:padding="1dp"
android:adjustViewBounds="true"
android:src="@drawable/test_image" />
Kindly note that android:adjustViewBounds="true"
works only with android:layout_width
and android:layout_height
set to "wrap_content".
If you put the padding=1 and the background color in the LinearLayout, you'll have a 1px yellow border.