Android启动画面横竖屏都支持

3

我该如何修改我的代码以为横屏和竖屏模式设置启动画面?我已经成功地在竖屏模式下工作了,现在希望能够适用于所有的方向。请修改这段代码。以下是我的SplashActivity.java。

public class SplashActivity extends Activity {


  // Splash screen timer
 private static int SPLASH_TIME_OUT = 3000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_screen);



    new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(SplashActivity.this, MainActivity.class);
            startActivity(i);

            // close this activity
             finish();
          }
       }, SPLASH_TIME_OUT);
    }

  }

这是我的splash_screen.xml文件。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" >


  <ImageView
     android:id="@+id/imgLogo"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:adjustViewBounds="true"
     android:scaleType="centerCrop"

     android:src="@drawable/screen_portrait"

     />
</RelativeLayout>

我不明白你的意思。它将如何检测正在运行的方向? - Salman Ullah Khan
2个回答

3

如果想在横屏界面上显示启动画面,请按以下步骤进行操作。

  1. res文件夹下创建文件夹layout-land
  2. 在该文件夹中复制splash_screen.xml文件。
  3. 将竖屏启动图片资源更改为您的横屏启动图片。

适当的文件将自动在运行时加载。无需更改Java代码


我还能使用 layout-land 吗?我试图使用它,但似乎对我没有起作用。 - natsumiyu
是的,你可以这样做。请确保你的活动在清单文件中不仅仅设置为纵向。 - Shabbir Dhangot

0

我认为你的清单文件有问题。请描述一下你的主要问题。

<activity
        android:name=".SplashActivity"
        android:configChanges="keyboard|orientation|screenSize"
        android:label="@string/app_name"
        android:theme="@style/AppLoginTheme"
        android:windowSoftInputMode="adjustResize" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接