在圆形ImageView外部创建边框 [英] Create a border outside the circular ImageView

查看:99
本文介绍了在圆形ImageView外部创建边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a circular ImageView, but I need to add a border outside the image.

这是代码:

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);

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

Could anybody help me to create a border outside the circular image?

推荐答案

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

First you create a circle shape like this,

    <?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>

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

Then add a relative layout and add an imageview to it.Arrange it to the center of relative layout.And set this circle shape as Imageview's background.Then place your circular imageview above previously added imageview.Arrange it also to center.By changing your circular imageview margin you will get the desired border effect.

最终代码

    <?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>

这篇关于在圆形ImageView外部创建边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆