我在我的应用程序中随FirebaseRecyclerAdapter和RecyclerView一起使用了Youtube API,出于某些原因,我的YouTube缩略图未显示在我的应用程序中,尽管我已将它添加到我的CardView
中, FirebaseRecyclerAdapter
有访问CardView
的代码,但是当我启动我的应用程序并转到该活动时,那里没有显示任何缩略图。如果没有Firebase适配器,我已将其实施为硬编码。CardView未在Android中显示Youtube缩略图
步骤我都试过:
新增布局管理器
调整cardView和thumbnailView
的高度和宽度
我使用过Android Studio
YouTube的类文件:
public class YoutubeVideos extends YouTubeBaseActivity {
private RecyclerView YouRecycler;
private DatabaseReference YDatabaseReference;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.youtube_videos);
YDatabaseReference = FirebaseDatabase.getInstance().getReference().child("youtubed");
YouRecycler = (RecyclerView)findViewById(R.id.Youtube_recycler);
}
@Override
public void onStart() {
super.onStart();
FirebaseRecyclerAdapter<post2youtube, YoutubeViewHolder> YfirebaseRecyclerAdapter = new FirebaseRecyclerAdapter<post2youtube, YoutubeViewHolder>(
post2youtube.class,
R.layout.youtube_videos_card,
YoutubeViewHolder.class,
YDatabaseReference
) {
@Override
protected void populateViewHolder(YoutubeViewHolder viewHolder, post2youtube model, int position) {
viewHolder.setYoutube(model.getYoutube());
}
};
YouRecycler.setAdapter(YfirebaseRecyclerAdapter);
}
public static class YoutubeViewHolder extends RecyclerView.ViewHolder {
View yView;
public YoutubeViewHolder(View YitemView) {
super(YitemView);
yView = YitemView;
}
public void setYoutube(final String youtube){
final YouTubePlayerView youPlay = (YouTubePlayerView) yView.findViewById(R.id.youtuber);
youPlay.initialize("Some key",
new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.loadVideo(youtube);
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
});
}
}
}
的YouTube RecyclerView文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id ="@+id/Youtube_recycler"/>
</LinearLayout>
的YouTube cardView XML文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/youtube_cardView"
android:layout_width="match_parent" android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtuber"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</android.support.v7.widget.CardView>
'Config'被示出的误差不能解析符号,如何删除它 –
我已经解决了配置,但它仍然没有显示,还有我放在卡片视图中的任何东西都没有显示 –
Config是一个类,其中DEVELOPER_KEY是静态缺点您可以在添加缩略图视图后使用任何其他类来代替Config –