我希望将YouTubePlayerFragment叠加到我的自定义listView视频上,但我收到错误[App不幸停止] .. 这是我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="20dip">
<EditText
android:id="@+id/userId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionGo"
android:inputType="text" />
<Button
android:id="@+id/searchButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="getUserYouTubeFeed"
android:text="Click to Search" />
<com.gagan.ui.widget.VideosListView
android:id="@+id/videosListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<com.gagan.ui.widget.VideosListView
android:id="@+id/videosListViewHistory"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<com.gagan.ui.widget.VideosListView
android:id="@+id/videosListViewFavourite"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerFragment"
android:id="@+id/youtube_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout >
活动代码:
youTubePlayerFragment.getView().setVisibility(View.VISIBLE);
fm.beginTransaction().setCustomAnimations(R.anim.fade_in,R.anim.fade_out);
fm.beginTransaction().add(R.id.videosListView,youTubePlayerFragment,"yt_id1");
fm.beginTransaction().addToBackStack(null);
fm.beginTransaction().commit();
player.setPlayerStateChangeListener(playerStateChangeListener);
this.playerInstance = player;
//player.cueVideo(videoID);
player.loadVideo(videoID);
我感兴趣的是:
1)有任何更正吗? 1)我错过了什么吗? 2)任何更好的设计或替代方案?
谢谢&amp;此致!
答案 0 :(得分:1)
获得解决方案......将布局更改为RelativeLayout,onCreate方法隐藏片段:
youTubePlayerFragment.getView().setVisibility(View.GONE);
&安培; on OnItemClickListener只是用参数实例化播放器并显示youtubefragment:
youTubePlayerFragment.getView().setVisibility(View.VISIBLE);
RelativeLayout会将[overlay]叠加在listView ..
上谢谢!