2016-03-22 12 views
1

私はAndroidのアプリケーションで、画像をクリックしてYouTube動画を再生したいと考えています。私は別のアクティビティや画面に移動したくありません。画像をクリックしてyoutube videoを再生するには?

さらに、画像に割り当てられたスペース以外の余分なスペースがビデオにはないようにします。

誰かが解決策を提案できますか? Androidに関する投稿は見つかりませんでした。 OnClickListenerに仮定し

答えて

1

ありがとうございました。それは私のアプリのためにうまくいった。私が最終的にどのようにしたのか説明しましょう。この目的のために、我々はビューを重ねることができる相対レイアウトが必要です。 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); 
     } 
    }); 
1

、あなたはクリックイベントをキャッチ:

1)あなたがそれにsetVisibility(View.GONE)を呼び出すことにより、画像が見えなくなるだろう。

2)あなたはYouTubePlayerSupportFragmentを拡張VideoFragmentクラスを持っているでしょうし、それが見えない容器に含まれることになるので、あなたは、詳細については

VideoFragment videoFragment = (VideoFragment) getFragmentManager().findFragmentById(R.id.video_fragment_container); 
videoFragment.setVideoId(videoId); 
container.setVisibility(View.VISIBLE); 

を呼び出すthe sample applicationsを見てみましょう。

+0

.Thanks。だから、私はビューを重ねることを提案していますか?それをクリックして動画が表示されると消える画像はありますか?そして、ビデオは同じ画像空間に収まりますか? –

関連する問題