onBackPressed()方向问题 [英] onBackPressed() Orientation Issue

查看:80
本文介绍了onBackPressed()方向问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Activity支持Landscape模式

   <activity
        android:name=".MainActivity"
        android:configChanges="orientation|screenSize|keyboardHidden"
        android:screenOrientation="landscape"
        android:label="@string/app_name" >

我已经为Video Player分配了50%的空间(使用FrameLayout),其余的50%分配给了ListView.

where I have allocated 50% space to Video Player (using FrameLayout) and rest 50% to ListView.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/video_frame"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <ListView
        android:id="@+id/video_list_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

</LinearLayout>

现在,我已经开始播放视频 > 移动到全屏模式模式> 退出全屏模式> 以人像模式获取活动(而我期望以横向模式进行活动)

Now, I have started playing video > moved to full screen mode > pressed back to exit full screen mode > getting Activity in Portrait mode (whereas I was expecting to get it in Landscape mode)

    boolean isFullScreen = false;

    @Override
    public void onGoToFullscreen() {
        isFullScreen = true;
        videoListView.setVisibility(View.INVISIBLE);
    }

    @Override
    public void onReturnFromFullscreen() {
        videoListView.setVisibility(View.VISIBLE);
    }

    @Override
    public void onBackPressed() {
        Log.d("boolean:-", Boolean.toString(isFullScreen));
        if(isFullScreen) {
            imaPlayer.getContentPlayer().setFullscreen(false);
        }
        else {
            super.onBackPressed();
        }
    }

推荐答案

/*我不确定,您可以将这行代码放到按后的方法上吗? */

/* I am not sure,can you put this line of code in on back pressed method ? */

Log.d("boolean:-", Boolean.toString(isFullScreen));
    if(isFullScreen) {
        imaPlayer.getContentPlayer().setFullscreen(false);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
    else {
        super.onBackPressed();
    }

这篇关于onBackPressed()方向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆