foreword
Every time I add an ImageView, I find that there is a discrepancy between the width and height I set and the width and height I want. After researching, I find that it is actually because the picture still has a certain distance of inner margin, which leads me to need a 100x100 picture. It looks only 60x60. So how can I easily see the actual size of this picture, so I thought, it’s not enough to add a border to the picture
accomplish
drawable——Create a new resource file as a background image
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<!--圆角边框-->
<!--
<corners android:radius="15dp" />-->
<!--虚线-->
<!--<stroke android:width="1dp"
android:color="#000000"
android:dashWidth="5dp"
android:dashGap="2dp"
/>-->
<stroke android:width="1dp"
android:color="#000000"/>
<padding
android:left="8dp"
android:top="8dp"
android:right="8dp"
android:bottom="8dp"
/>
</shape>
Then on the picture that needs to be set as a border, just reference the background to this file
example
layout file
...
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/level_fragment_shadow"
android:background="@drawable/test_border"
/>
...
Implementation diagram: