English 中文(简体)
带有 XML 布局并添加按钮到 Canvas 的机器人表面视图
原标题:android Surface View with XML Layout and add buttons to a Canvas

所以我用画布做了表面视图, 所以我可以做一些图形。 有没有办法用画布做 xml 版面布局, 这样我就可以有按钮,什么不在屏幕上, 或者在画布上做按钮还有其他选择吗?

最佳回答

您必须制造一个有画布的类。 然后在 xml 版式中导入该类 。

例如:FingerPaint examples

上面的例子就是 我的View类 包含画布来利用它。

您需要做的是:

首先在您的 xml 中创建如下任意布局 :

<RelativeLayout
        android:id="@+id/drawingLayout"     
        android:layout_width="wrap_content"     
        android:layout_height="wrap_content">

    </RelativeLayout>

现在让我们假设主. xml 是您的主要 xml 版式文件, 然后在版式中添加该类, 如下面的版式 :

   setContentView(R.layout.main);

    drawingLayout = (RelativeLayout)findViewById(R.id.drawingLayout);
    System.out.println("The Layout is: "+drawingLayout);
    myView = new MyView(this);
    drawingLayout.addView(myView);

但愿你明白我的意思 否则就通知我

享受:))

问题回答

是的,是的,您可以对布局有按钮视图, 但是它们会存在于 Canvas 之外, 但是它们也可以覆盖画布。 或者您可以直接将您自己的按钮放在表面, 并且通过写入自己触摸检测的顶部。 如果您要为游戏创建一个小框架( 或者类似“ spreite ” 的游戏), 那么顶部就是您正在做的事情。 使这些按钮看起来完全像按钮视图可能有点困难, 但这是可能的 。

这最终要由设计决定什么是比较容易或更好的执行。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签