如何在android IconGenerator上居中文本

编程入门 行业动态 更新时间:2024-10-28 21:26:26
本文介绍了如何在android IconGenerator上居中文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用地图上放置的大量标记开发应用程序,并且我正在使用自定义 ClusterRenderer 来显示它们.问题是我无法在自定义标记图标的中心绘制集群的大小,请参阅附加的屏幕截图.我尝试将 contentPadding 添加到 IconGenerator,但仍然没有运气,因为显示的数字数量不断变化.你能帮我把文本放在生成的图标上吗?

I'm developing an app using lots of markers placed on the map, and I'm using a custom ClusterRenderer to show them. Problem is that I can't draw the cluster's size in the center of the custom marker icon, please see attached screenshot. I've tried adding contentPadding to the IconGenerator, but still no luck, because of the changing number of digits shown. Could you please help me center the text on the generated icon?

代码:

IconGenerator clusterIconGenerator = new IconGenerator(context); clusterIcon = context.getResources().getDrawable(R.drawable.map_cluster); clusterIconGenerator.setBackground(clusterIcon); @Override protected void onBeforeClusterRendered(Cluster<MyType> cluster, MarkerOptions markerOptions) { Bitmap clusterIcon = clusterIconGenerator.makeIcon(String.valueOf(cluster.getSize())); markerOptions.icon(BitmapDescriptorFactory.fromBitmap(clusterIcon)); }

推荐答案

UPDATE

从 2016 年 4 月 1 日开始,库的资源中添加了前缀因此 id="text" 已更改为 "amu_text".

如图书馆文档中所述:

setContentView public void setContentView(View contentView) 设置图标的子视图. 如果视图包含一个id为amu_text"的TextView,操作如setTextAppearance(Context, int) 和 makeIcon(String) 会操作在那个 TextView 上.

setContentView public void setContentView(View contentView) Sets the child view for the icon. If the view contains a TextView with the id "amu_text", operations such as setTextAppearance(Context, int) and makeIcon(String) will operate upon that TextView .

@Override protected void onBeforeClusterRendered(Cluster<Dashboard_Marker> cluster, MarkerOptions markerOptions) { IconGenerator TextMarkerGen = new IconGenerator(context); Drawable marker; int ClusterSize = cluster.getSize(); marker = context.getResources().getDrawable(R.drawable.cluster_red); TextMarkerGen.setBackground(marker); LayoutInflater myInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View activityView = myInflater.inflate(R.layout.cluster_view, null, false); TextMarkerGen.setContentView(activityView); TextMarkerGen.makeIcon(String.valueOf(cluster.getSize())); BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(TextMarkerGen.makeIcon()); markerOptions.icon(icon); }

布局 cluster_view 为:

with the layout cluster_view as :

<LinearLayout xmlns:android="schemas.android/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:layout_centerInParent="true" android:layout_centerVertical="true" android:weightSum="1"> <TextView android:layout_width="61dp" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Medium Text" android:textColor="#000000" android:id="@+id/amu_text" android:layout_marginTop="13dp" android:gravity="center" /> </LinearLayout>

注意:: 布局必须包含一个id = "amu_text" 的文本视图,以便图标生成器接受它,在布局中操纵所有你想要的定位.

note :: the layout must contain one text view with an id = "amu_text" in order for the icon generator to accept it , manipulate all the positioning you want in the layout .

更多推荐

如何在android IconGenerator上居中文本

本文发布于:2023-05-30 09:22:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/365379.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   如何在   android   IconGenerator

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!