SplashScreen 上的手势叠加

Gesture Overlay on SplashScreen

我正在尝试在用作初始屏幕的 activity 上使用手势叠加。

问题是当我:gOverlay = (GestureOverlayView) this.findViewById(R.id.gOverlay); 时,gOverlay 为空。

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center" android:background="#000000"
android:weightSum="1">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.11">
    <android.gesture.GestureOverlayView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/gOverlay"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:visibility="visible"
        android:background="#000000"
        >
    </android.gesture.GestureOverlayView>
 </RelativeLayout>

 </LinearLayout>

这是 Splash java 代码:

   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    /** set time to splash out */

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        Duration = extras.getString("Duration");
    }
    welcomeScreenDisplay = 4000;
    try {
        welcomeScreenDisplay = Integer.parseInt(Duration);
    } catch (Exception x) {
    }

    gLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);

    if (!gLibrary.load()) {
        finish();
    }
    gOverlay = (GestureOverlayView) this.findViewById(R.id.gOverlay);
    gOverlay.setGestureVisible(false);
    gOverlay.addOnGesturePerformedListener(this);

    /** create a thread to show splash up to splash time */
    Thread welcomeThread = new Thread() {
        int wait = 0;

        @Override
        public void run() {
            try {
                super.run();

                while (wait < welcomeScreenDisplay) {
                    sleep(100);
                    wait += 100;
                }
            } catch (Exception e) {
                System.out.println("EXc=" + e);
            } finally {

                finish();
            }
        }
    };
    welcomeThread.start();

}

我想做的是: 1. 当用户按下后退按钮时,将显示启动画面。 2.这个闪屏会在屏幕上停留n秒 3. 如果用户在初始屏幕上绘制 'L',隐含在手势叠加层上,main activity 将 .finish()

谢谢

从你给出的评论来看,你似乎在膨胀错误的布局。

你说过,包含 GestureOverlayView 的布局名为 splash2。

setContentView(R.layout.splash);

但是你在给 splash 充气,而不是 splash2。如果 splash.xml 不包含带有 android:id="@+id/gOverlay"GestureOverlayView,则从 splash 请求 gOverlay 将抛出空指针。

将 activity 中的 setContentView() 更改为以下内容应该会有所帮助:

setContentView(R.layout.splash2);