首页 > 解决方案 > 如何在 Kotlin 中将 View 转换为 Imageview

问题描述

fun tap(view: View) {

    val img = view
 }

我希望这个变量 img 是一个图像视图,但我想知道如何将视图转换为图像视图。

标签: androidkotlinviewcastingimageview

解决方案


请尝试如下投射:

val img: ImageView = view as ImageView

推荐阅读