【发布时间】:2021-04-27 18:05:27
【问题描述】:
我正在构建一个音乐播放器应用程序。
所有歌曲都显示在回收站视图中。
点击任何歌曲时,我想:
- 显示表示歌曲当前正在播放的视图(频谱/波)。
这应该只对当前播放的歌曲可见。
RcvLayoutAllSongs.xml
<TextView
android:id="@+id/txt_artist_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textColor="@color/artist_name_color"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="@+id/constraintLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
android:layout_marginEnd="30dp"
app:layout_constraintStart_toStartOf="@+id/txt_song_name"
app:layout_constraintTop_toBottomOf="@+id/txt_song_name"
app:layout_constraintVertical_bias="0.0" />
<es.claucookie.miniequalizerlibrary.EqualizerView
android:id="@+id/equalizer_view"
android:layout_width="30dp"
android:layout_height="30dp"
app:animDuration="3500"
android:visibility="gone"
app:foregroundColor="@color/bottom_music_stroke"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/txt_song_name"
app:layout_constraintTop_toTopOf="parent" />
我想做的就是:-
使 equalizer_view 仅对被点击的项目可见,如果可能的话,更改被点击项目的 textview 的颜色
SongsAdapter
override fun onBindViewHolder(holder: AllSongsViewHolder, position: Int) {
val song = songs[position]
with(holder) {
with(songs[position]) {
binding.txtSongName.text = song.title
binding.txtArtistName.text = song.subtitle
//on click
binding.rootLyt.setOnClickListener {
onItemClickListener?.let { click ->
click(song)
//here I will handle click to display the view on only selected item
}
}
}
}
}
private var onItemClickListener: ((Songs) -> Unit)? = null
fun setOnItemClickListener(listener: (Songs) -> Unit) {
onItemClickListener = listener
}
override fun getItemCount() = songs.size
这种方法的问题是我还想在歌曲暂停时使视图不可见..这是在片段中处理的......不是适配器
歌曲片段
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.pauseView.setOnClickListener {
//this is where I pause the song when the song is clicked from the adapter, I
also want to make the wave/view invisible from the adapter but don't know how
mainViewModel.pauseSong
}
}
【问题讨论】:
-
点击item时创建界面,然后在recycler视图中调用removeDataSetChanged(position)
标签: android xml android-studio kotlin