Android ImageView设置边框

ImageView设置边框其实很简单,一个shape就能搞定,无需自定义image view。

shape_gray_square_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <corners android:radius="1.0px" />
    <stroke android:color="@color/divider_color" android:width="2px"/>
    <solid android:color="@android:color/white" />

</shape>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

imageview设置:

<ImageView
            android:id="@+id/display_image"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:padding="1dp"
            android:scaleType="centerInside"
            android:background="@drawable/shape_gray_square_bg"
            android:layout_marginLeft="@dimen/dp_6"
            android:layout_marginRight="@dimen/dp_6"
            />
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

注意加上 android:padding=”1dp”,效果更好!

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net

猜你喜欢

转载自www.cnblogs.com/skiwnchhw/p/10473078.html