在过去的几个小时里,我一直在摆弄新的DreamService API,它非常可爱。不过,我确实有一个问题。
我想在显示DreamService时将屏幕方向锁定为横向。DreamService的用途是显示大量宽屏照片,我不希望屏幕顶部和底部出现黑条。
我已经尝试了很多方法,包括Java代码中的setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)和清单文件中的android:screenOrientation="landscape",但都没有成功。
这让我想知道:是否可以锁定DreamService的方向
发布于 2013-01-28 00:22:57
Android开发团队证实,在一段时间前的一次现场开发人员闲聊中,这目前是不可能的。
我相信谷歌希望DreamServices在两个屏幕方向都能工作,所以这是不可能的原因。
发布于 2016-10-12 20:22:34
解决方法:使用此库https://github.com/rongi/rotate-layout
build.gradle
dependencies {
compile 'rongi.rotate-layout:rotate-layout:2.0.0'
}your_daydream_layout.xml
<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>和btw:允许自动旋转你的白日梦..来自https://code.google.com/p/android/issues/detail?id=40226
“看起来这个问题的修复已经实现了(没有人告诉我们)。不幸的是,它不能正常工作。在我的Nexus 6p (6.0.1,Build #MHC19Q)上,如果我滑动到最左边的屏幕(Google Now?),点击左上角的汉堡菜单,选择设置,然后转到底部,就会有一个“允许旋转”的主屏幕选项。启用后,主屏幕将能够在需要时旋转到横向。然后,白日梦也可以继承旋转并以横向模式显示。“-- 2016年5月18日
发布于 2014-11-07 06:40:31
遗憾的是,我也没有找到任何解决方案,我不得不使用一个糟糕的变通办法,它可能对你也可能不起作用,就是在设置布局之前,将自动旋转设置设为关闭:
在您的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);
<...>在您的清单中:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />https://stackoverflow.com/questions/13850611
复制相似问题