gpt4 book ai didi

android - 应用程序始终在平板电脑中显示横向模式

转载 作者:行者123 更新时间:2023-11-30 04:00:40 24 4
gpt4 key购买 nike

我做了一个在模拟器和中小型手机上运行良好的应用程序。但是在平板电脑上运行时,它总是只显示横向模式。我也使用了单独的布局和布局土地布局。我是不明白背后的原因。这是代码:

public class SplashActivity extends FragmentActivity
{
public void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
requestWindowFeature(1);
getWindow().setFlags(1024, 1024);

FragmentManager fragmentmanager = getSupportFragmentManager();
FragmentTransaction fragmenttransaction = fragmentmanager.beginTransaction();
if (getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(0);
}
else
{
setRequestedOrientation(1);
}
fragmenttransaction.commit();

setContentView(R.layout.welcome);
new Handler().postDelayed(new SplashThread(), 2000L);
}

class SplashThread implements Runnable
{
SplashThread()
{
}

public void run()
{
SplashActivity.this.startActivity(new Intent(SplashActivity.this, McqHomePage.class));
SplashActivity.this.finish();
}
}
}

请帮助我。提前致谢。

最佳答案

如果您不关心方向,您不妨完全省略这段代码:

if (getResources().getConfiguration().orientation == 
Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(0);
}
else
{
setRequestedOrientation(1);
}

上面的代码还有一个丑陋的副作用,即某些方向的改变总是会导致纵向——例如,反向横向不会被您的代码捕捉到。此外,请使用提供的常量而不是 0 或 1,这样即使值发生变化,您的代码也不会中断。

与此同时,检查您的 manifest -- 我打赌你在那里添加了一个方向属性。

关于android - 应用程序始终在平板电脑中显示横向模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12549942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com