【问题标题】:Use View.isInEditMode() in your custom views with CordovaWebView在带有 CordovaWebView 的自定义视图中使用 View.isInEditMode()
【发布时间】:2015-05-08 05:06:20
【问题描述】:

我正在使用 CordovaWebView 开发应用程序,并且我在 web_view.xml 文件中添加了以下代码。

<org.apache.cordova.CordovaWebView
        android:id="@+id/cordovaWebView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

我已经实现了 CordovaInterface 的方法。现在我的设计页面显示以下错误消息。

提示:在自定义视图中使用 View.isInEditMode() 来跳过代码 在 Eclipse 中显示

谁能告诉我如何解决它?

【问题讨论】:

    标签: eclipse android-custom-view cordovawebview cordova-5.0.0


    【解决方案1】:

    isInEditMode()应该在自定义视图构造函数中使用。试试下面的代码:

    public class GraphView extends View implements Grapher
        {
    
         public GraphView(Context context, AttributeSet attrs) {
                super(context, attrs);
                if(!isInEditMode())
                 init(context);
            }
    
            public GraphView(Context context) {
                super(context);
               if(!isInEditMode()){
                touchHandler = new TouchHandler(this);
                init(context);
              }
            }
    

    用您的 CordovaWebview 替换 GraphView。

    View.isInEditMode()

    指示此视图当前是否处于编辑模式。当在开发人员工具中显示时,视图通常处于编辑模式。例如,如果此视图是由可视化用户界面构建器绘制的,则此方法应返回 true。如果子类的正常行为可能会干扰宿主环境,则应检查此方法的返回值以提供不同的行为。例如:类在其构造函数中产生一个线程,绘图代码依赖于特定于设备的功能等。此方法通常在自定义小部件的绘图代码中进行检查。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      相关资源
      最近更新 更多