Android DreamService的锁定屏幕方向

Android DreamService的锁定屏幕方向,android,android-4.2-jelly-bean,dreamservice,Android,Android 4.2 Jelly Bean,Dreamservice,在过去的几个小时里,我一直在摆弄新的,它非常可爱。不过,我有一个问题 我想在显示DreamService时将屏幕方向锁定为横向。DreamService的目的是显示大量宽屏照片,我不希望屏幕顶部和底部都有黑条 我已经尝试了很多方法,包括Java代码中的setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u横向),以及清单文件中的android:screenOrientation=“横向”,但都没有成功 这让我想知道:是否有可能锁定梦

在过去的几个小时里,我一直在摆弄新的,它非常可爱。不过,我有一个问题

我想在显示
DreamService
时将屏幕方向锁定为横向。
DreamService
的目的是显示大量宽屏照片,我不希望屏幕顶部和底部都有黑条

我已经尝试了很多方法,包括Java代码中的
setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u横向)
,以及清单文件中的
android:screenOrientation=“横向”
,但都没有成功


这让我想知道:是否有可能锁定
梦想服务的方向?

安卓开发团队确认,在不久前的一次开发者现场闲逛中,这目前是不可能的


我相信谷歌想让DreamServices在两个屏幕方向上都工作,所以这就是为什么不可能的原因。

很遗憾,我也没有找到任何解决方案,我不得不使用一种恶劣的解决方法,在设置布局之前,设置自动旋转设置,这可能对你有用,也可能对你无效:

在您的DreamService课程中:

import android.provider.Settings;
<...>

    @Override
public void onAttachedToWindow() {

    Settings.System.putInt(getContentResolver(),
            android.provider.Settings.System.ACCELEROMETER_ROTATION, 0);

    setContentView(R.layout.dream_main);
<...>
导入android.provider.Settings;
@凌驾
公共空间和附加的Towindow(){
Settings.System.putInt(getContentResolver(),
android.provider.Settings.System.Accelerator\U旋转,0);
setContentView(R.layout.dream_main);
在您的舱单中:

<uses-permission android:name="android.permission.WRITE_SETTINGS" />

解决方法:使用此库

格雷德尔先生

您的_daydream_layout.xml



顺便说一句: 允许自动旋转你的白日梦..从

“看来这方面的解决方案已经实施了(而且没有人告诉我们) 不幸的是,它不能正常工作。在我的Nexus 6p(6.0.1)上, Build#MHC19Q),如果我滑动到最左边的屏幕(Google Now?),点击 在左上角的汉堡包菜单中,选择设置,然后转到 底部,有一个“允许旋转”的主屏幕选项 启用后,主屏幕将能够旋转到横向 当需要的时候,白日梦可以继承旋转和旋转 也以横向模式显示。”——2016年5月18日

 dependencies {
        compile 'rongi.rotate-layout:rotate-layout:2.0.0'
    }
<com.github.rongi.rotate_layout.layout.RotateLayout  
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   app:angle="-90">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <WebView
        android:id="@+id/daydream_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#2a2e31" />

    <TextView
        android:id="@+id/dream_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif-light"
        android:text="..."
            android:textColor="#abc"
            android:textSize="20sp" />
    </RelativeLayout>
</com.github.rongi.rotate_layout.layout.RotateLayout>