gpt4 book ai didi

android - DialogFragment 中的 VideoView

转载 作者:太空宇宙 更新时间:2023-11-03 11:17:18 24 4
gpt4 key购买 nike

我刚刚创建了一个自定义的 DialogFragment,里面有一个 VideoView,但我遇到了一些问题。

  • 视频正在播放,但是不知为何,视频的顶部有一层黑色的透明层。当然,我尝试从我的应用程序中的其他地方播放相同的视频,这不是对话窗口,但它显示正确。很奇怪...

  • 此外,对话框窗口的顶部和左侧边框消失了 - 如果移除 VideoView,它们也不会消失。

有什么想法吗?提前致谢!

编辑

Controller

public class VideoPlayerFragment extends DialogFragment
{
String json_string;

// Constructor
public static VideoPlayerFragment newInstance(String json_string_arg)
{
VideoPlayerFragment fragment = new VideoPlayerFragment();

Bundle arguments = new Bundle();
arguments.putString("json_string", json_string_arg);
fragment.setArguments(arguments);

return fragment;
}


@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

// Set style
setStyle(DialogFragment.STYLE_NO_TITLE, 0);
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.video_player, container, false);

return view;
}


@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);

// Set video holder
VideoView video_view = (VideoView) getView().findViewById(R.id.video_view);

// Set URL
Uri video = Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + R.raw.test);
video_view.setVideoURI(video);

// Start video
video_view.start();
}
}

查看

    <LinearLayout android:id="@+id/video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/video_player_margin"
android:orientation="vertical" >

<VideoView android:id="@+id/video_view"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="700dp"
android:layout_height="400dp" />

</LinearLayout>

最佳答案

     public class VideoPlayerFragment extends DialogFragment
{
String json_string;

// Constructor
public static VideoPlayerFragment newInstance(String json_string_arg)
{
VideoPlayerFragment fragment = new VideoPlayerFragment();

Bundle arguments = new Bundle();
arguments.putString("json_string", json_string_arg);
fragment.setArguments(arguments);

return fragment;
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = new Dialog(getActivity());
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
dialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN|WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
dialog.setCancelable(true);
View parent= getActivity().getLayoutInflater().inflate(R.layout.video_player, null);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
dialog.setContentView(parent, layoutParams);
return dialog;
}
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);

// Set video holder
VideoView video_view = (VideoView) getView().findViewById(R.id.video_view);

// Set URL
Uri video = Uri.parse("android.resource://" + getActivity().getPackageName() + "/" + R.raw.test);
video_view.setVideoURI(video);

// Start video
video_view.start();
}

friend 试试上面的代码。不要创建 View ,而是尝试创建没有对话框标题的 onCreateDialog ....

关于android - DialogFragment 中的 VideoView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14522439/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com