Android 如何使videoview全屏显示,并在其上方放置一个关闭图像视图?
这是我尝试过的代码Android 如何使videoview全屏显示,并在其上方放置一个关闭图像视图?,android,android-videoview,android-framelayout,Android,Android Videoview,Android Framelayout,这是我尝试过的代码 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/activity_video_player" android:layout_width="match_parent" android:layout_height="match_parent"> <
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_video_player"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
/>
<ImageView
android:layout_gravity="top|right"
android:src="@android:drawable/ic_menu_close_clear_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
但是最终的布局是这样的
如何使视频占据全屏并关闭图像视图应在视频上方的右上角显示?试试这个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" />
</RelativeLayout>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:src="@drawable/placeholder" />
</RelativeLayout>
这里是诀窍
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:fitsSystemWindows="true"
/>
<ImageView
android:layout_gravity="top|right"
android:src="@android:drawable/ic_menu_close_clear_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
你用的很好。您可以使用“相对布局”和“帧布局”来实现与“布局”_gravity=top | right”相同的效果,以便在关闭图像视图时使用。@tahsinRupam我尝试了您的代码,但它不起作用。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<ImageView
android:id="@+id/close_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="@drawable/button_close" />
</RelativeLayout>