在YoutubePlayerFragment

时间:2017-08-25 07:56:53

标签: android xml android-fragments youtube-api

我正在学习在我的片段上添加YouTube视频,一切都很好,直到我按全屏。退出全屏后,屏幕处于横向模式。

FragmentTwo.java代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    View view =  inflater.inflate(R.layout.fragment_fragment_two, container, false);
    textView = view.findViewById(R.id.textView_title);
    YouTubePlayerSupportFragment youTubePlayerFragment = new YouTubePlayerSupportFragment();
    youTubePlayerFragment.initialize(getString(R.string.youtube_api_key), this);
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(R.id.frame_video, youTubePlayerFragment);
    fragmentTransaction.commit();

    //Get the title of the video 
    textView.setText(getArguments().getString("1"));
    return view;
}

@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
    if(!b) {
        youTubePlayer.cueVideo(getArguments().getString("8"));
    }
}

@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
    Toast.makeText(getContext(), "Fail", Toast.LENGTH_SHORT).show();
}

我的.xml文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/youtube_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.gameapp.FragmentTwo">

<!-- TODO: Update blank fragment layout -->


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/frame_video"
        android:layout_width="match_parent"
        android:layout_height="250sp"
        android:layout_alignParentLeft="true"></FrameLayout>

    <TextView
        android:id="@+id/textView_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/frame_video"
        android:paddingBottom="5dp"
        android:paddingRight="5dp"
        android:textColor="@android:color/black"
        android:textSize="15sp" />
</RelativeLayout>

我尝试将所有布局的方向设置为“垂直”但没有任何反应。我必须按下按钮才能摆脱它,这太不方便了。有人能告诉我如何解决这个问题吗?提前谢谢!

0 个答案:

没有答案