【发布时间】:2016-02-04 21:09:50
【问题描述】:
我正在尝试在用作启动屏幕的 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”,隐含在 Gesture Overlay 上,主要活动将 .finish()
谢谢
【问题讨论】:
-
请添加您分配
gOverlay的来源。你确定,你夸大了正确的布局吗? -
显示你在哪里声明
gOverlay的代码(如果你这样做了)。 -
不要做启动画面。 每次 用户启动您的应用时,您都在浪费他们的时间。你的应用可能不值得。
-
启动画面很有用。如果您需要在启动应用程序之前做一些工作。但它更像是一个加载屏幕。
-
“这是我的 XML”的名称是什么?这是“R.layout.splash”吗?
标签: android splash-screen android-gesture