android - dialogFragment 中的视频全屏模式
问题描述
我正在使用此代码从自定义适配器打开一个片段对话框:
HomeActivity activity = (HomeActivity) (context);
FragmentManager fm = activity.getSupportFragmentManager();
editor.putString("post_media", remainder);
editor.apply();
PostVideoFragment alertDialog = new PostVideoFragment();
alertDialog.show(fm, "fragment_alert");
这是片段对话框的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<VideoView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
这是片段对话框的代码:
public class PostVideoFragment extends DialogFragment {
VideoView post_video;
public static String MISDATOS= "MisDatos";
SharedPreferences prefs;
SharedPreferences.Editor editor;
String post_media;
public static PostVideoFragment newInstance() {
PostVideoFragment fragment = new PostVideoFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_post_video, container, false);
prefs = getActivity().getSharedPreferences(MISDATOS, Context.MODE_PRIVATE);
editor = prefs.edit();
post_media = prefs.getString("post_media", "no");
String url = "https://f..postsmedia/";
final VideoView videoView;
videoView = (VideoView)v.findViewById(R.id.video);
videoView.setVideoPath(url+post_media);
videoView.start();
return v;
}
}
功能是正确的,可以播放视频,但是当屏幕处于横向模式时我需要全宽播放它,现在它只以非常小的模式显示。
这是输出:
人像模式:
横向模式:
解决方案
在onStart
您的DialogFragment
中,您可以将高度和宽度设置为MATCH_PARENT
如下所示:
@Override
public void onStart()
{
super.onStart();
Dialog dialog = getDialog();
if (dialog != null)
{
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width, height);
//You need to add below lines in order to show FullScreen VideoView without the status bar
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
推荐阅读
- bison - “轻松”转变/减少冲突
- python-3.x - 读取具有动态值的 sql 文件
- java - 错误:MainActivity.java 上需要类、接口或枚举
- c# - 如何为我的相机设置后期处理图层?
- vscode-settings - 无法在 VSCode 中使用“editor.suggest.showKeywords”禁用语言“关键字”建议:false
- docker - Docker 运行更改密码到 SQL Server 容器
- php - WooCommerce 和 Shippo - Shippo 订单 Obj ID 存储?
- python - 如何将其他文件包含到包中?
- python - 如何将 SWIG 类型图应用于_only_ 特定函数?
- git - 如何使用 git 分支获取新功能