获得一个gestureoverlayview [英] Getting a gestureoverlayview

查看:100
本文介绍了获得一个gestureoverlayview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用上我的Andr​​oid画图一些很好的教程。我想也加入这里找到凉爽的手势演示:

I have been using some nice tutorials on drawing graphics on my android. I wanted to also add in the cool gesture demo found here:

http://developer.android.com/resources/articles/gestures.html

这需要code的这些行:

That takes these lines of code:

GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.addOnGesturePerformedListener(this); 

这是很好,很正常,但我在试玩意识到我尝试使用code从图形与Android中播放建设。该演示是有意义的,一切是有道理的,但我发现用:

This is fine and dandy yet I realize in my demo i'm trying to build using code from "Playing with Graphics in Android". The demos make sense, everything makes sense but I found out by using:

setContentView(new Panel(this));

作为被玩弄的图文教程需要,那么findViewById似乎不再有效,并返回null。起初我要发布一个傻问题,为什么发生这种情况,与玩的setContentView快速测试让我认识的findViewById返回null,我只是不知道如何解决这个问题的原因。请告诉我关键我在这里失踪?我认识到,新的面板doinking一些参考了,但我不知道如何使连接在这里。

as is required by the Playing With Graphics tutorials, then the findViewById seems to no longer be valid and returns null. At first I was about to post a stupider question as to why this is happening, a quick test of playing with the setContentView made me realize the cause of findViewById returning null, I just do not know how to remedy this issue. Whats the key I am missing here? I realize that the new Panel is doinking some reference up but I am not sure how to make the connection here.

的:
R.id.gestures
定义正确的诠释,他的main.xml为:(就像教程)

The: R.id.gestures is defined right int he main.xml as: (just like the tutorial)

<android.gesture.GestureOverlayView
    android:id="@+id/gestures"
    android:layout_width="fill_parent" 
    android:layout_height="0dip"
    android:layout_weight="1.0" />

所以,我没有证实

So I did confirm the

setContentView(new Panel(this))

造成问题。所以我知道的问题是,我必须弄清楚如何将android.gesture.GestureOverlayView添加到面板类不知何故,我只是不知道如何去了解这一点。

is causing the issue. So I know the issue is that I have to figure out how to add the android.gesture.GestureOverlayView to the panel class somehow, I am just not sure how to go about this.

此战之后,我大致知道我需要什么刚才怎么做它做。我想我需要在main.xml中创建一个面板或搞清楚如何在main.xml中建立什么为code手势或者同等学历。我靠近,因为我这样做:
    GestureOverlayView手势=新GestureOverlayView(本);

After fighting with this I generally know what I need to do just now how to do it. I think I need either the equivalent of creating a panel in that main.xml OR figuring out how to build whats in main.xml for the gestures in code. I am close because I did this: GestureOverlayView gestures = new GestureOverlayView(this);

这让我一个非空的手势现在,不幸的是,因为我不告诉它填补随时随地家长,我不认为它真的显示出来,所以我想很难搞清楚布局PA公羊。难道我连在正确的轨道?

which gets me a non null gestures now, unfortunately since I am not telling it to fill Parent anywhere I don't think its really showing up, so I am trying hard to figure out layout pa rams. Am I even on the right track?

推荐答案

为了为 findViewById 来工作,它需要知道哪些布局文件的情况下使用。这就是的setContentView 是。既然你定义main.xml中的布局,你需要调用

In order for findViewById to work it needs to know which layout file the context is using. That's what setContentView is for. Since you defined the layout in main.xml, you'll need to call

setContentView(R.layout.main);

(而不是其他任何调用的setContentView的)告诉那是它应该使用的布局活动。一旦你这样做, findViewById 就知道到哪里寻找ID为姿态的说法。

(instead of any other call to setContentView) to tell the activity that that's the layout it's supposed to use. Once you do that, findViewById will know where to look for the View with ID "gestures".

这篇关于获得一个gestureoverlayview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆