如何动态地将 ImageView 添加到 View
我想制作一副纸牌。我有一个名为 Deck (Deck 类扩展 View)的视图,我已将其设置为 ContentView,并且我想动态地将卡片作为 ImageView 添加到 Deck 上。我搜索了很多(谷歌,论坛),但找不到一种可以理解它是如何工作的方法,所以我想我会问这个菜鸟问题..
如果我有 ImageView 卡,我该如何添加它到视图平台以及如何指定它的确切放置位置?我不想创建 XML 布局,因为那样我就必须在 xml 上手动添加 52 张卡片作为 ImageView。我想动态地执行此操作,但布局处理让我感到困惑。感谢帮助或指点,谢谢。另外,我不想使用画布,因为我无法确定哪个卡位图位于另一个卡位图之上。
I want to create a deck of cards. I have a view called Deck (class Deck extends View) which I have set as the ContentView and I want to add the cards as ImageViews on the Deck, dynamically. I have searched a lot (google,forums) and I can't find a way that I can understand how it works, so I thought I'd ask this noob question..
If I have an ImageView card, how do I add it to the View deck and how do I specify where exactly it should be placed? I don't want to create an XML layout, because then I will have to add 52 cards by hand on the xml as ImageViews. I want to do this dynamically, and the layout handling has me confused. Help or pointers appreciated, thanks. Also, I dont want to use a canvas because I have no way of determining which card bitmap is on top of another.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将这样做:
Here is how I would do it: