繁体   English   中英

带有定向支持的飞溅活动

[英]Splash activity with orientation support

我希望我的启动活动支持垂直和水平方向。

飞溅活动的代码如下

public class Splash extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    Thread timer = new Thread(){
        public void run() {
            try{
                sleep(5000);    

            }catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent ARCActivityIntent = new Intent("com.ex.rc.LISTSCREEN");
                startActivity(ARCActivityIntent);// 
                finish();
            }
        }};

    timer.start();

    }

}

splash.xml的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal|center_vertical"
    android:background="@drawable/splash_bg"
    >
</LinearLayout>

但问题是-重新创建了LISTSCREEN活动,更改了方向。

帮我。

我有一个类似的问题。 我把它修好了。 这是解决方案。 仅为启动屏幕创建一种布局,但为LANDSCAPEPORTRAIT创建不同的图像。 由于您只有一种布局,即纵向,因此不会重新创建活动。 但是背景图像会改变,从而提供方向改变的效果。

在onCreate中写下以下代码。

setContentView(R.layout.splash);

splashImage = (ImageView) findViewById(R.id.splash_img);

int orient = getWindowManager().getDefaultDisplay().getOrientation();
if (orient == 0) {
         splashImage.setBackgroundResource(R.drawable.splash_portrait);
} else {
         splashImage.setBackgroundResource(R.drawable.splash_landscape);
}

重写onConfigurationChanged方法

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    int orient = getWindowManager().getDefaultDisplay().getOrientation();
    if (orient == 0) {
        splashImage.setBackgroundResource(R.drawable.splash_portrait);
    } else {
        splashImage.setBackgroundResource(R.drawable.splash_landscape);
    }
}

清单中的SplashActivity应该如下所示

    <activity
        android:name="SplashActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

这对我有用...

在清单中:将方向更改为android:screenOrientation="unspecified"

从初始布局中删除所有Oriantation,例如android:orientation="vertical"

    <activity
        android:name="com.gr8ly.gr8lysymbolshortcutkeys.Splash"
        android:label="@string/app_name"
        android:screenOrientation="unspecified"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM