我想在android中更改下面的群集图标。在一个圆圈中将有一个图像视图和一个文本视图。
我的自定义图标代码
private class ItemRenderer extends DefaultClusterRenderer<ClusterPopupList> {
private final IconGenerator mIconGenerator = new IconGenerator(getApplicationContext());
private final IconGenerator mClusterIconGenerator = new IconGenerator(getApplicationContext());
private final int mDimension;
public ItemRenderer() {
super(getApplicationContext(), map, mClusterManager);
View multiProfile = getLayoutInflater().inflate(R.layout.multi_profile,null);
mClusterIconGenerator.setContentView(multiProfile);
mImageView = new ImageView(getApplicationContext());
mDimension = (int) getResources().getDimension(R.dimen.custom_profile_image);
mImageView.setLayoutParams(new ViewGroup.LayoutParams(mDimension, mDimension));
mIconGenerator.setContentView(mImageView);
}
@Override
protected void onBeforeClusterItemRendered(ClusterPopupList item, MarkerOptions markerOptions) {
mImageView.setImageResource(item.profilePhoto);
Bitmap icon = mIconGenerator.makeIcon();
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
super.onBeforeClusterItemRendered(item, markerOptions);
}
@Override
protected void onBeforeClusterRendered(Cluster<ClusterPopupList> cluster, MarkerOptions markerOptions) {
List<Drawable> profilePhotos = new ArrayList<Drawable>(Math.min(4, cluster.getSize()));
int width = mDimension;
int height = mDimension;
for (ClusterPopupList p : cluster.getItems()) {
// Draw 4 at most.
if (profilePhotos.size() == 4) break;
Drawable drawable = getResources().getDrawable(p.profilePhoto);
drawable.setBounds(0, 0, width, height);
profilePhotos.add(drawable);
}
Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
}
@Override
protected void onClusterRendered(Cluster<ClusterPopupList> cluster, Marker marker) {
super.onClusterRendered(cluster, marker);
}
@Override
public ClusterPopupList getClusterItem(Marker marker) {
return super.getClusterItem(marker);
}
@Override
protected boolean shouldRenderAsCluster(Cluster<ClusterPopupList> cluster) {
return cluster.getSize() > 1;
}
}
multi_profile.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@android:color/transparent"
android:src="@drawable/icon_cluster_count"/>
<TextView
android:id="@id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/Bubble.TextAppearance.Light"
android:paddingLeft="@dimen/custom_profile_padding"
android:paddingRight="@dimen/custom_profile_padding"
android:layout_below="@id/image"
android:text="150"
android:layout_centerHorizontal="true"
android:layout_marginBottom="8dip"
android:textColor="@color/theme_color"
android:alpha=".8"/>
</RelativeLayout>
输出:
我希望像圆圈中的第一张图片一样实现群集图标。我在相对布局中使用了圆形背景,但这不起作用。
答案 0 :(得分:0)
来自the Google Maps documentation site:
自定义标记簇
ClusterManager
构造函数会创建DefaultClusterRenderer
和NonHierarchicalDistanceBasedAlgorithm
。您可以使用ClusterRenderer
和setAlgorithm(Algorithm<T> algorithm)
更改setRenderer(ClusterRenderer<T> view) methods of ClusterManager
和算法。
您可以实施ClusterRenderer
来自定义群集的呈现。 DefaultClusterRenderer
提供了一个良好的基础。通过继承DefaultClusterRenderer
,您可以覆盖默认值。
答案 1 :(得分:0)
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.collections import PolyCollection
import matplotlib.pyplot as plt
from matplotlib import colors as mcolors
import numpy as np
fig = plt.figure(num=99,figsize=(3.25,2.25), dpi=300)
ax = fig.gca(projection='3d')
def cc(arg):
return mcolors.to_rgba(arg, alpha=0.6)
xs = np.arange(0, 10, 0.4)
verts = []
zs = [0.0, 1.0, 2.0, 3.0]
for z in zs:
ys = np.random.rand(len(xs))
ys[0], ys[-1] = 0, 0
verts.append(list(zip(xs, ys)))
poly = PolyCollection(verts)#, facecolors=[cc('r'), cc('g'), cc('b'),
# cc('y')])
poly.set_alpha(0.7)
ax.add_collection3d(poly, zs=zs, zdir='y')
ax.set_xlabel('X')
ax.set_xlim3d(0, 10)
ax.set_ylabel('Y')
ax.set_ylim3d(-1, 4)
ax.set_zlabel('Z')
ax.set_zlim3d(0, 1)
#make z-axis disappear
ax.w_zaxis.line.set_lw(0.)
ax.set_zticks([])
# make some of the panes transparent
ax.xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
ax.yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
# make the grid lines transparent
ax.xaxis._axinfo["grid"]['color'] = (1,1,1,0)
ax.yaxis._axinfo["grid"]['color'] = (1,1,1,0)
ax.zaxis._axinfo["grid"]['color'] = (1,1,1,0)
答案 2 :(得分:0)
使用它删除背景
mClusterIconGenerator.setBackground(null)
将背景设置为给定的Drawable,或删除背景。 @param background Drawable用作背景,或者为null以删除背景。