音乐播放器-RecyclerView缓慢且缓慢

时间:2018-07-29 13:05:46

标签: android-recyclerview picasso recycler-adapter recyclerview-layout

我正在尝试创建一个音乐播放器android应用程序,在其中添加了“专辑”部分。我使用MediaStore成功检索了所有数据,问题是在滚动没有图像的图像时recyclerView速度很慢,它工作起来很流畅。

请参阅下面用于在onBindViewHolder中获取专辑封面的代码

 @Override
public void onBindViewHolder(@NonNull SongsAdapter.ViewHolder holder, int position) {
    Song song = songs.get(position);
    holder.songName.setText(song.title);
    holder.artistName.setText(song.artistName);

    Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
    Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, song.albumId);

    Picasso.get()
            .load(albumArtUri)
            .fit()
            .into(holder.albumArt);
}

项目的xml文件在下面

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:padding="2dp"
    android:id="@+id/linearLayout"
    android:background="@color/white"
    >

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardUseCompatPadding="true"
        app:cardCornerRadius="6dp">

        <ImageView
            android:id="@+id/album_art_album"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:src="@color/colorPrimary"/>

    </android.support.v7.widget.CardView>

    <TextView
        android:id="@+id/album_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Black Sabbath"
        android:maxLines="1"
        android:textSize="16sp"
        android:layout_marginLeft="6dp"
        android:textColor="#000"
        android:layout_marginBottom="3dp"

        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/album_artist"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Black Sabbath"
            android:maxLines="1"
            android:textSize="12sp"
            android:layout_marginLeft="6dp"
            android:ellipsize="end"
            />

        <TextView
            android:id="@+id/album_songs_count"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="(2)"
            android:maxLines="1"
            android:textSize="12sp"
            android:layout_marginLeft="6dp"
            android:ellipsize="end"
            />

    </LinearLayout>

</LinearLayout>

获取图像以在recyclerView中显示的有效方法是什么?我在做错什么吗?

0 个答案:

没有答案