- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用XML布局实现Google map 中的自定义 map 标记。
然而;当我使用createCustomMarker
方法将自定义标记打印到Google Maps中时,它不会加载/显示来自云/服务器的图像。
我认为这是因为Glide(或此事中的应用)在布局转换成Bitmap之前没有完成更改以完成下载和渲染图像,或者我的实现是错误的。谁能帮我这个?
@SuppressLint("InflateParams")
private fun createCustomMarker(urlImageFromCloud: String): Bitmap{
val marker: LayoutInflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view: View = marker.inflate(R.layout.map_marker, null)
val messageIcon: Int = resources.getIdentifier("local_image_from_drawable", "drawable", this.packageName)
val markerPhoto: CircleImageView = view.findViewById(R.id.map_photo)
val markerContainer: CircleImageView = view.findViewById(R.id.map_photo)
val options: RequestOptions = RequestOptions()
.centerCrop()
.placeholder(R.color.colorGrayWhite)
.error(R.color.colorGrayWhite)
.diskCacheStrategy(DiskCacheStrategy.ALL)
Glide.with(this)
.load(urlImageFromCloud) // String image URL from my server/cloud - this is the part that does not show up.
.apply(options).into(markerPhoto)
Glide.with(this)
.load(messageIcon)
.apply(options).into(markerContainer)
val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
view.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels)
view.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels)
view.buildDrawingCache()
val bitmap = Bitmap.createBitmap(view.measuredWidth, view.measuredHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
view.draw(canvas)
return bitmap
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_marker_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/map_container"
android:layout_width="75dp"
android:layout_height="75dp"/>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/map_photo"
android:src="@color/colorGray"
android:layout_marginTop="5dp"
android:layout_centerHorizontal="true"
style="@style/MapMarkerCircleImage"/>
</RelativeLayout>
createCustomMarker
方法的方式。
val defaultLocation = LatLng(locationLatitude, locationLongitude)
googleMap.addMarker(MarkerOptions().position(defaultLocation).icon(BitmapDescriptorFactory.fromBitmap(createCustomMarker("my_image_url_from_cloud"))))
最佳答案
我遇到过同样的问题。我的解决方案是使用Glide下载位图,并在完成下载后使用侦听器创建标记。
private fun getMarkerIcon(context: Context, url: String, listener: (BitmapDescriptor) -> Unit) {
val markerView = View.inflate(context, R.layout.view_marker, null)
Glide.with(context)
.asBitmap()
.load(url)
.into(object : SimpleTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
markerView.avatarImageView.setImageBitmap(resource)
listener.invoke(BitmapDescriptorFactory.fromBitmap(getBitmapFromView(markerView)))
}
})
}
private fun getBitmapFromView(view: View): Bitmap {
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
val bitmap = Bitmap.createBitmap(view.measuredWidth, view.measuredHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
view.layout(0, 0, view.measuredWidth, view.measuredHeight)
view.draw(canvas)
return bitmap
}
getMarkerIcon(context, "http://....") {
val options = MarkerOptions()
.position(LatLng(latitude, longitude))
.icon(it)
googleMap.addMarker(options)
}
关于android - Android Kotlin-使用带有Glide的Bitmap实现自定义 map 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55359248/
从 Gilde 3.7.0 迁移到 Glide 4.9.0。 如下定义我的 MyAppGlideModule。 @GlideModule public class MyAppGlideModule
我将 Glide JS 用于我使用 ACF 和 Gutenberg Blocks 构建的幻灯片。 但是下一个按钮有问题。 ">"无法正确呈现 - 它会破坏整个 DOM。 “data-glide-dir
我到处搜索,但因为 Glide 已经发布了 4.4 版。我再也找不到应用 RoundedCornersTransformation 的方法了。我正在使用 glide-transformations甚至
我想调整 gif 文件的大小并保存它。我尝试使用一些建议的方法,但这些方法会出错,后来我才知道 Glide v4 中不推荐使用某些方法 byte[] bytes = Glide.
我正在尝试使用 firebase 在 android studio 中开发一个消息应用程序。根本没有语法错误。但是当我使用实现 'com.github.bumptech.glide:glide:4.8
这是我的代码: d.setBounds(15, 8, d.getIntrinsicWidth(), d.getIntrinsicHeight()); ImageSpan span = new Imag
我很难从 firebase 存储中获取图像 URL,我从数据库中获取了照片 URL,但据我所知,Glide 无法从这样的链接获取图片:com.google.firebase .storage.Uplo
我使用 Glide我的应用程序中的库内部自定义适配器 View 。但我有错误: "You must not call setTag() on a view Glide is targeting" 我的
我试图添加编译 应用程式 bulid.gradle compile 'com.github.bumptech.glide:glide:3.7.0' 当我尝试运行该应用程序时,它给了我错误 NoCla
我尝试了所有可能的方法,但无法弄清楚如何在我的 json 更新时更新图像以滑动 我的 android 应用程序最初使用 glide 从 json 加载图像,之后它只从缓存加载图像。它不会加载在服务器上
首先我集成了 Room 数据库并将一些信息存储到 db,其中包含一些图像 URL,现在我需要在 ImageViews 中显示这些图像。 现在尝试使用 glide,添加依赖项和注释处理器, 实现'com
我的房车有问题。我正在将 mp3 的封面艺术加载到字节数组中,然后使用 glide 将字节数组加载到图像中 (vh.coverArt)。但是,当我使用 glide 而不是仅使用 .SetImageBa
简单的 Glide.with(context).load(url).into(image) 在将项目与 同步后无法正常工作 compile 'com.github.bumptech.glide:gli
我真的为 Rails 的所有新 JS 更改而苦苦挣扎。我正在尝试实现非常简单的 slider 脚本 Glide.js 这是我的 app/javascripts/packs/front.js 文件: /
Build.gradle(模块:App) apply plugin: 'com.android.application' android { compileSdkVersion 23
我正在创建一个应用程序,让用户通过按 ImageView 来更改他/她的图像,该图像将来自他/她的图库并将上传到我的 FirebaseStorage 中。用户的个人详细信息单独上传到 Firebase
我可以通过滑动将图像成功加载到 ImageView 中,并使用 .circularCrop() 方法对其进行裁剪。 Glide.with(this) .load("https://i.img
使用 glide 在 recyclerview imageview 项目上加载图像。受阻 Glide 听众我意识到图像资源已准备好,但图像未显示在 imageview 中。当我在 Glide 监听器
我在我的应用程序中使用 glide 加载图像。它在我的情况下工作正常,比如 if(image_enabled==1){ Glide.with(getContext()).load(constant.S
是否可以使用 缓存图像? Glide 未在 imageView 中显示?.如果是那怎么办? 现在我正在做这个代码: Glide .with(getApplicationContext()) .
我是一名优秀的程序员,十分优秀!