Android - Set a border around an ImageView

前端 未结 9 1317
旧时难觅i
旧时难觅i 2021-02-06 23:50

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

相关标签:
9条回答
  • 2021-02-07 00:22

    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"/>
    
    0 讨论(0)
  • 2021-02-07 00:24

    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".

    0 讨论(0)
  • 2021-02-07 00:27

    If you put the padding=1 and the background color in the LinearLayout, you'll have a 1px yellow border.

    0 讨论(0)
提交回复
热议问题