我需要在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
首先在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
。是的,那将解决您的问题。
您可以通过这种方式实现。
<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>
这样,您将获得相同的输出。