在圆形ImageView外部创建边框

1 android border android-imageview

我创建了一个圆形ImageView,但我需要在图像外添加边框.

这是代码:

Bitmap circleBitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);   
BitmapShader shader = new BitmapShader (bitmap,  TileMode.CLAMP, TileMode.CLAMP);

Paint paint = new Paint();
paint.setShader(shader);
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);      
paint.setColor(Color.parseColor("#BAB399"));

Canvas c = new Canvas(circleBitmap);        
c.drawARGB(0, 0, 0, 0);
c.drawCircle(50, 40,40, paint);
Run Code Online (Sandbox Code Playgroud)

有人可以帮我在圆形图像外面创建一个边框吗?

Bas*_*rif 8

首先你创建一个像这样的圆形,

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
    <gradient android:startColor="#333440" android:endColor="#333440"
        android:angle="270"/>
</shape>
Run Code Online (Sandbox Code Playgroud)

然后添加相对布局并向其添加一个imageview.将其放置到相对布局的中心.然后将此圆形设置为Imageview的背景.然后将圆形图像视图放在先前添加的imageview上方.将它也放到中心.通过更改圆形imageview边距您将获得所需的边框效果.

最终代码,

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="30dp">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/imageView14"
            android:background="@drawable/circ"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageView15"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/linked"
            android:layout_margin="5dp" />
    </RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述