【问题标题】:How to get a slide transition in phonegap?如何在phonegap中获得幻灯片过渡?
【发布时间】:2012-04-16 11:05:22
【问题描述】:

我在 Stackoverflow 上看到了很多关于使用 phonegap 开发应用程序时两个 html 页面之间的故障/间隔/间隙的问题。我找到了一个用于phonegap 的插件slider plugin。经过大量搜索后,我无法弄清楚如何执行此步骤 3。

Add the import for your resource Java file (yourpackage.R) to LoadingSpinner.java

这在我看来像是原生代码,但我无法理解。

我的问题是:

  1. yourpackage.R 文件是什么??
  2. 它在哪里??
  3. 那里给出的第 3 步该怎么做??

谢谢

------------编辑-----------

这里是R.java的内容

    package com.somethingsomething.appone;

    public final class R {
        public static final class attr {
        }
        public static final class drawable {
            public static final int ic_launcher=0x7f020000;
        }
        public static final class layout {
            public static final int main=0x7f030000;
        }
        public static final class string {
            public static final int app_name=0x7f060001;
            public static final int hello=0x7f060000;
        }
        public static final class style {
            public static final int loading_spinner=0x7f050000;
        }
        public static final class xml {
            public static final int cordova=0x7f040000;
            public static final int plugins=0x7f040001;
        }
    }

LoadingSpinner.java 的内容是

    package de.sandstein.phonegap.plugin.transition;

    import android.app.Dialog;
    import android.content.Context;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.ProgressBar;

    public class LoadingSpinner extends Dialog {

            public static LoadingSpinner show(Context context, CharSequence title,
                    CharSequence message) {
                return show(context, title, message, false);
            }

            public static LoadingSpinner show(Context context, CharSequence title,
                    CharSequence message, boolean indeterminate) {
                return show(context, title, message, indeterminate, false, null);
            }

            public static LoadingSpinner show(Context context, CharSequence title,
                    CharSequence message, boolean indeterminate, boolean cancelable) {
                return show(context, title, message, indeterminate, cancelable, null);
            }

            public static LoadingSpinner show(Context context, CharSequence title,
                    CharSequence message, boolean indeterminate,
                    boolean cancelable, OnCancelListener cancelListener) {
                LoadingSpinner dialog = new LoadingSpinner(context);
                dialog.setTitle(title);
                dialog.setCancelable(cancelable);
                dialog.setOnCancelListener(cancelListener);
                /* The next line will add the ProgressBar to the dialog. */
                dialog.addContentView(new ProgressBar(context), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                dialog.show();

                return dialog;
            }

            public LoadingSpinner(Context context) {
                super(context, R.style.loading_spinner);
            }
    }

在 LoadingSpinner.java 中导入 R.java 为

 import android.R;

现在是错误状态

loading_spinner cannot be resolved or is not a field

------------编辑-----------

在 LoadingSpinner.java 文件中将 android.R 替换为 com.somethingsomething.appone.R

 import com.somethingsomething.appone.R;

仍然是错误状态

loading_spinner cannot be resolved or is not a field

清理项目并重新启动eclipse,错误就消失了。

用法说

    1) Call initTransition() on startup of the app.
    2) Call showLoadingView() to show the loading view. (Android: can use parameter "animation" ('slide' oder 'fade'))
    3) When the animation has finished 'transitionAnimationReady' is fired.
    4) Call hideLoadingView() to hide the loading view.

我在哪里可以找到声明这些全局函数以便它适用于所有文件的地方。

它应该在其他文件中,在html标签上方的html文件中,在head标签中。尝试将以下代码放在 html 上方和 head 标记中。

<script type="text/javascript" charset="utf-8" src="transition.js"></script>
<script type="text/javascript">
    initTransition();
    showLoadingView('slide');
    hideLoadingView();
    alert("hi");
</script>

【问题讨论】:

    标签: java android plugins cordova transition


    【解决方案1】:
    1. 我没有使用 phonegap,但是就 android 而言,“你的包”。R 是一个系统生成的 java 文件,它存储了一个 int id,对于你在应用程序中使用的每个 id 都是唯一的。这包括布局、字符串值等。

    2. 由于它是系统生成的,它存储在应用程序的 gen 文件夹中

    3. 如果您熟悉 java,它只是一个普通的导入。

    只需查看ref,您就会对 R.java 了解很多

    【讨论】:

    • "导入 com.somethingsomething.appone.R;"因为你正在做的将使用android的默认R.java。
    猜你喜欢
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-20
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    相关资源
    最近更新 更多