且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在圆形ImageView外部创建边框

更新时间:2023-10-22 14:06:16

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

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>