我需要在 ImageView 上设置一个圆形
这是我迄今为止尝试过的:
float[] outerR = new float[]{8, 8, 8, 8, 8, 8, 8, 8};
RoundRectShape roundrect = new RoundRectShape(outerR, null, null);
ShapeDrawable drawable = new ShapeDrawable(roundrect);
这提供了椭圆形。我需要一个圆形。如何解决这个问题?谢谢
我需要在 ImageView 上设置一个圆形
这是我迄今为止尝试过的:
float[] outerR = new float[]{8, 8, 8, 8, 8, 8, 8, 8};
RoundRectShape roundrect = new RoundRectShape(outerR, null, null);
ShapeDrawable drawable = new ShapeDrawable(roundrect);
这提供了椭圆形。我需要一个圆形。如何解决这个问题?谢谢
您可以通过这种方式实现。
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_email_black_24dp"/>
<TextView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="end"
android:gravity="center"
android:background="@drawable/bg_circle"
android:text="5"
android:textColor="@android:color/white"/>
</FrameLayout>
bg_circle
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/holo_red_dark"/>
<size android:height="10dp"
android:width="10dp"/>
<corners android:radius="10dp"/>
</shape>
这样,您将获得相同的输出。
xml drawable
首先在你的文件夹中创建一个文件drawable
进入该res
目录。然后在该xml
文件中粘贴以下代码:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666666"/>
<size
android:width="50dp"
android:height="50dp"/>
</shape>
并将其设置drawable
为background
您的textView
. 是的,这将解决你的问题。