Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 动态更改ListView项目大小kotlin_Android_Kotlin - Fatal编程技术网

Android 动态更改ListView项目大小kotlin

Android 动态更改ListView项目大小kotlin,android,kotlin,Android,Kotlin,我正试图以编程方式更改ListView项的高度和宽度,但我得到一个“val无法重新分配错误”,您能否告诉我无法在此处重新分配val,以及如何最终设置列表的高度和宽度是我的自定义适配器 class Game6Adapter( private val mContext: Context, private val resourceLayout: Int, private val items: ArrayList<Drawable> ) : ArrayAdap

我正试图以编程方式更改ListView项的高度和宽度,但我得到一个“val无法重新分配错误”,您能否告诉我无法在此处重新分配val,以及如何最终设置列表的高度和宽度是我的自定义适配器

    class Game6Adapter(
    private val mContext: Context,
    private val resourceLayout: Int,
    private val items: ArrayList<Drawable>
) : ArrayAdapter<Drawable>(mContext, resourceLayout, items) {

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        var v: View? = convertView

        var vi: LayoutInflater = LayoutInflater.from(mContext)
        v = vi.inflate(resourceLayout, null)


        val p = getItem(position)


        var imageView = v!!.findViewById(R.id.game_6_item_image) as ImageView
        imageView.setImageDrawable(items[position])

        var layoutParams = parent.layoutParams
        imageView.height = (parent.height * 0.1).toInt() // val cannot be reassigned
        imageView.width = (parent.height * 0.1).toInt()  val cannot be reassigned
        imageView.requestLayout()


        return v!!
    }
}
class Game6适配器(
private val mContext:Context,
私有val资源布局:Int,
私有val项:ArrayList
):ArrayAdapter(mContext、resourceLayout、items){
覆盖视图(位置:Int,convertView:View?,父级:ViewGroup):视图{
变量v:视图?=转换视图
变量vi:LayoutInflater=LayoutInflater.from(mContext)
v=vi.充气(resourceLayout,空)
val p=getItem(位置)
var imageView=v!!.findViewById(R.id.game\u 6\u item\u image)作为imageView
imageView.setImageDrawable(项目[位置])
var layoutParams=parent.layoutParams
imageView.height=(parent.height*0.1).toInt()//无法重新分配val
imageView.width=(parent.height*0.1).toInt()值无法重新分配
imageView.requestLayout()
返回v!!
}
}

对您的问题的零碎回答:

imageView
内部的
height
width
字段是不可变的(
val
):

因为我不知道也看不到类/接口
ImageView
的实现,所以我不能说如何实现更改

var imageView = v!!.findViewById(R.id.game_6_item_image) as ImageView