【问题标题】:Gesture Overlay on SplashScreenSplashScreen 上的手势叠加
【发布时间】: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


【解决方案1】:

从您提供的 cmets 来看,您似乎在夸大错误的布局。

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

setContentView(R.layout.splash);

但你是在膨胀 splash,而不是 splash2。如果 splash.xml 不包含 GestureOverlayViewandroid:id="@+id/gOverlay",则从 splash.xml 请求 gOverlay 将抛出一个空指针。

将您的活动中的setContentView() 更改为以下应该会有所帮助:

setContentView(R.layout.splash2);

【讨论】:

  • 我没有看到我使用了另一个内容视图。谢谢:)
  • 没问题。但请注意@323go 所说的内容。大多数闪屏都会惹恼用户。所以尽可能避免它们。
  • 我会的。你知道如何从初始屏幕完成主要活动吗?
  • 通常你会在开始活动 B 后立即完成活动 A。startActivity(intent); finish(); 就是这样。
  • 不,我想在某些情况下完成 SplashScreen 和 Main Activity:比如 -> 用户在 SplashScreen 上绘制“L”字母
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多