我正在使用Android上的應用程序,在該應用程序中,我想在點擊圖像後播放YouTube視頻。我不想進入不同的活動或屏幕。如何在點擊圖像時播放YouTube視頻?
另外我不希望視頻佔用分配給圖像的空間以外的任何額外空間。
有人可以提出任何解決方案嗎?我沒有發現任何關於Android的帖子。
我正在使用Android上的應用程序,在該應用程序中,我想在點擊圖像後播放YouTube視頻。我不想進入不同的活動或屏幕。如何在點擊圖像時播放YouTube視頻?
另外我不希望視頻佔用分配給圖像的空間以外的任何額外空間。
有人可以提出任何解決方案嗎?我沒有發現任何關於Android的帖子。
感謝您的幫助。這對我的應用程序確實很好。讓我解釋我是如何最終做到的。爲此我們需要相對佈局,我們可以在其中重疊視圖。我重疊了ImageView和youtubeView。最初,我將ImageView設置爲VISIBLE,將youtubeView設置爲INVISIBLE。在ImageView的View.onClickListener中,我將ImageView設置爲INVISIBLE,將youtubeView設置爲VISIBLE。這對我來說很好。
注意:除非要創建自己的自定義佈局,否則視圖重疊只能在RelativeLayout中使用,不能在任何其他佈局中使用。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingStart="@dimen/activity_horizontal_margin_less"
android:paddingRight="@dimen/activity_horizontal_margin_less"
android:paddingTop="@dimen/activity_vertical_margin_less"
android:paddingBottom="@dimen/activity_vertical_margin_less"
tools:context="com.example.puneet.movieout.MovieInfoDisplay"
>
<TextView
android:layout_width="wrap_content"
android:id="@+id/textView2"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="I am Puneet Chugh. I am Puneet Chugh"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="@color/black"/>
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtube_view"
android:layout_below="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
/>
<ImageView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:id="@+id/imageView"
android:layout_below="@+id/textView2"/>
</RelativeLayout>
活動部分:
youTubeView.setVisibility(View.INVISIBLE);
moviePoster.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
moviePoster.setVisibility(View.INVISIBLE);
youTubeView.setVisibility(View.VISIBLE);
}
});
在OnClickListener假設,你趕上click事件:
1)您將使圖像隱形通過調用它setVisibility(View.GONE)
。
2)你將有一個VideoFragment
類,它擴展YouTubePlayerSupportFragment
,它會被包含在一個無形的容器,所以你打電話
VideoFragment videoFragment = (VideoFragment) getFragmentManager().findFragmentById(R.id.video_fragment_container);
videoFragment.setVideoId(videoId);
container.setVisibility(View.VISIBLE);
有關詳情,看看the sample applications。
.Thanks你的答案。那麼,你是否建議我可以重疊觀點?當我點擊它並且視頻出現時,我可以看到圖像消失嗎?視頻適合相同的圖像空間? –