如何创建带图片标记的自定义Drawable定位标记图标
创建样式一致的自定义地图标记图标
我看你正在做一个带背景的自定义地图标记,用RelativeLayout搭配CircleImageView的思路很靠谱!我把你的布局代码整理成规范格式,还补全了CircleImageView的常用属性,方便你直接参考:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/user_marker_layout" android:layout_width="50dp" android:layout_height="50dp" android:background="@drawable/ic_map_person_circle"> <de.hdodenhof.circleimageview.CircleImageView android:id="@+id/user_marker_avatar" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="4dp" android:src="@drawable/default_avatar" app:civ_border_color="#ffffff" app:civ_border_width="1dp"/> </RelativeLayout>
另外给你几个小建议,让标记的样式和交互更完善:
- 给CircleImageView设置
android:layout_margin,避免头像和背景边框贴得太紧,视觉上更协调 - 可以把固定的
50dp换成wrap_content,再配合android:minWidth="50dp"和android:minHeight="50dp",适配不同尺寸的头像素材 - 如果需要标记支持点击交互,给RelativeLayout加上
android:clickable="true"和android:focusable="true",再配合selector背景实现点击反馈效果
内容的提问来源于stack exchange,提问作者Jayyrus
相关产品推荐
相关产品推荐

