我正在Android上的一个应用程序上工作,我想在该应用程序上单击图像即可播放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);
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句