Android:画布层上的 UI 元素
如何在画布上(顶部)设置一些 UI 元素?
我有一个简单的触摸游戏,其图形放置在带有画布的自定义视图上。然而,由于我的全屏面板位于 setContentView() 中,我无法添加任何 UI 项目,例如进度条或徽标。我希望整个画布层可见,一些对象(进度条、徽标)“浮动”在其上方。
主类:
public class GameClass extends Activity implements OnGestureListener {
Panel panel;
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
panel = new Panel(this, 1, 2);
setContentView(Panel);
...
}
Panel类:
public class Panel extends View {
public Panel(Context context, int Var1, int Var2) {
super(context);
...
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
...
}
}
如代码所示,触摸在GameClass内部处理,动画的变化在Panel内部处理。
或者也许..是否可以使用进度条和按钮启动新的透明活动,以便覆盖活动上的按钮和底层活动上的对象都可用?我可能需要一种方法来使用透明活动上的按钮关闭所有层(透明活动、面板、游戏类)。复杂的? :D
How do I set some UI elements over (on top of) canvas?
I have a simple touch game that has its graphics placed on custom view with canvas. However as my full screen Panel is in the setContentView() I can't add any UI items like progressBar or logo. I would like to have whole canvas layer visible with some objects (progressBar, logo) "floating" over it.
Main class:
public class GameClass extends Activity implements OnGestureListener {
Panel panel;
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
panel = new Panel(this, 1, 2);
setContentView(Panel);
...
}
Panel class:
public class Panel extends View {
public Panel(Context context, int Var1, int Var2) {
super(context);
...
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
...
}
}
As code shows, touches are handled inside GameClass and the changes in animation are handled inside Panel.
Or maybe.. Would it be possible to start new transparent activity with progress bar and button so that both the button on overlay activity AND objects on underlying activity? And I could need a way to close all the layers (transparent activity, Panel, GameClass) with the button on transparent activity. Complicated? :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确实有同样的问题,这是我解决它的方法,
而不是将 contentview 设置为面板添加它 Linearlayout 添加到我的 game.xml 中,这是我的
I do have the same problem and here is how I solved it
instead of setting contentview to panel adding it Linearlayout that is added in my game.xml and here goes my