从列表视图位置更改图像Alpha

问题描述 投票:0回答:1

我正在制作音乐列表视图。我有一个基本适配器,音乐课音乐课具有3个属性;名称:字符串点:字符串图片:Int如何更改图像Alpha选中了哪个项目?

        listMusics.setOnItemClickListener { parent, view, position, id ->
        val preference = getSharedPreferences("PREFS",0)
        val editor = preference.edit()
        best1 = preference.getInt("best1", 0)
        if(best1>=position*100) {
            music = position
            imgMusic.alpha = 1F
            editor.putInt("music", music)
            editor.apply()
        }

    }

我正在用imgMusic.alpha = 1F进行更改,但是它只是在列表视图项上的第一个位置更改,我想更改Alpha,哪个项被选中,我该怎么做?

android android-studio listview kotlin baseadapter
1个回答
0
投票

我认为如果您使用ImageView显示图像,则可以使用此属性:

<ImageView
    android:layout_width="30dp"
    android:layout_height="35dp"
    android:id="@+id/imageView"
    android:alpha="0.4" // <-----------------  this
    android:background="@drawable/imagename"
/> 

希望对您有帮助

© www.soinside.com 2019 - 2024. All rights reserved.