Android 自定义View +标准元素...怎么样?
我已经在 Android 应用程序上工作了一段时间了,我正在尝试为其设计一个 UI。我已经使用标准 XML + Java 方法创建了几个,但一个屏幕需要一个自定义视图(使用绘图创建一种网格),其下方有一个小 TextView 和两个按钮。这个自定义视图似乎无法合理地扩展现有的视图(尽管如果可以的话,这可能会让事情变得更容易),所以我要么使用 XML + Java 布局并将自定义视图集成到其中,要么使用严格的Java 创建布局。在研究了两者之后(除了前者的崩溃或空白屏幕之外什么也没有得到),我一直在研究 Java 布局,但似乎无法在自定义视图下显示任何内容。
我已经研究了很多教程,但我似乎无法从它们中得到任何有用的东西,而且 Android 开发人员资源对于此类事情也不是很详细。如果有人能指出我正确的方向来实现这个功能,那就太好了。
I've been working away at an Android app for a while now and I'm trying to get a UI off the ground for it. I've created already created several with the standard XML + Java approach, but one screen requires a custom View (using draw to create a sort of grid) with a small TextView beneath it and two buttons beneath that. It doesn't seem that this custom View can reasonably extend existing ones (although if it can, that might make things easier), so I'm left with either using the XML + Java layout and integrating the custom View into that or using strict Java to create the layout. After digging around with both (and getting nothing but crashes or blank screens with the former), I've been mucking around with the Java layout, but can't seem to get anything to show up beneath the custom View.
I've dug through many tutorials, but I can't seem to get anything working from them and the Android developer resources aren't very detailed with this sort of thing. If someone can point me in the right direction to get this functioning, that would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 XML 中的自定义视图:
You can use custom views from XML:
下面是一个自定义视图的示例,其中包含许多标准视图(例如其下方的按钮)。自定义视图只需添加到 linerLayout 中即可: http:// /about-android.blogspot.com/2010/07/2d-graphics-with-effects_11.html
Here is an example of a custom view with many standard views like buttons below it. The custom view is simply added into a linerLayout: http://about-android.blogspot.com/2010/07/2d-graphics-with-effects_11.html