我需要在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);这提供了一个椭圆形。我需要一个圆形的。如何解决这个问题?Thx

发布于 2019-10-08 22:36:50
首先,在drawable文件夹中的res目录中创建一个xml drawable文件。然后将以下代码粘贴到该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设置为textView的background。是的,这会解决你的问题。
发布于 2019-10-08 22:38:48
你可以通过这样做来实现。
<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>这样,您将获得相同的输出。
https://stackoverflow.com/questions/58288161
复制相似问题