对话框中的视频全屏模式

时间:2019-06-07 12:49:34

标签: android 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>

这是fragmentdialog的代码:

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;
    }
}

功能是正确的,可以播放视频,但是当屏幕处于横向模式时,我需要全屏播放,现在只能以很小的模式显示。

以下是输出:

肖像模式:

enter image description here

风景模式:

enter image description here

2 个答案:

答案 0 :(得分:1)

关于对话框的大小,我也有类似的问题,为我解决的是用LayoutParams定义对话框的大小,如下所示:

Window window = yourDialog.getWindow();
if (window != null) {
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(window.getAttributes());

//This makes the dialog take up the full width
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
window.setAttributes(lp);
}

但是为什么不能只将XML对话框设置为match_parent并结束呢?

似乎默认对话框LayoutParams(wrap_content,wrap_content)覆盖了XML(match_parent,match_parent)中的LayoutParams。

这就是为什么您可以使用固定大小(150dp,150dp)并看到对话框大小发生变化的原因,但是对话框将不会响应,因此这不是一个明智的解决方案。

答案 1 :(得分:1)

cell的{​​{1}}中,您可以将高度和宽度设置为reloaded,如下所示:

<button mat-button disabled="!isAccessible(item.name)">Action1</button>