【问题标题】:onBackPressed() Orientation IssueonBackPressed() 方向问题
【发布时间】:2016-03-19 05:43:02
【问题描述】:

Activity支持Landscape模式

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

我已将 50% 的空间分配给 Video Player(使用 FrameLayout),其余 50% 分配给 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>

现在,我已经开始播放视频 > 移到全屏模式> 按回退出全屏模式> 在纵向模式下获得活动(而我希望在横向模式下获得它)

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

【问题讨论】:

标签: android android-activity android-manifest android-orientation exoplayer


【解决方案1】:

/* 我不确定,你能把这行代码放在背压方法上吗? */

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

【讨论】:

  • 现在当我点击返回时,我会在横向模式下查看视图,但是当我点击视频播放器中的按钮退出完整模式时,仍然会进入纵向模式,为什么?
  • 在onResume()方法中放这行代码并检查setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-14
  • 2012-12-30
  • 2011-10-24
相关资源
最近更新 更多