在Android中,如何在添加儿童时在FrameLayout中设置其顺序? [英] In Android, how can I set the order of children in a FrameLayout as they're added?

查看:173
本文介绍了在Android中,如何在添加儿童时在FrameLayout中设置其顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个FrameLayout,它将保存一组ImageViews.我使用FrameLayout是因为我实际上希望它们重叠.但是,当我将项目添加到布局时,我不希望它们只是堆叠.我实际上需要订购它们.

I have a FrameLayout that will hold a set of ImageViews. I'm using FrameLayout because I actually want them to overlap. However, as I add items to the Layout I don't want them to just stack. I actually need to order them.

图像从表单存储中拉出,并且我的正确顺序存储在数据库中,因此:

The image are pulled form storage and I have their correct order stored in my database so:

Image1 - layerNumber: 3
Image2 - layerNumber: 12
Image3 - layerNumber: 1
Image4 - layerNumber: 34
Image5 - layerNumber: 6
Image6 - layerNumber: 30

当我将它们放置在FrameLayout中时,需要按layerNumber顺序将它们放置在Layout中.另外,我将在使用该应用程序时一次添加一个或多个.我可能会选择添加"Image50-layerNumber:10"的内容.

When I place them in the FrameLayout I'll need to them to in the Layout in the layerNumber order. Also, I'll be adding one or more at a time as I use the app. I may tab something that adds "Image50 - layerNumber: 10".

我希望做的是使用诸如ImageView.setChildOrder(x)之类的东西.有什么办法吗?

What I was hoping to do was use something like ImageView.setChildOrder(x) or something like that. Is there any way of doing this?

-----编辑----- 根据@fifarunnerr,我做了这样的事情:

----- edit ----- per @fifarunnerr I did something like this:

productLayers.addView(productIV, Integer.parseInt(productItem.get(1)));

productItem.get(1)只是layerNumber.对于此示例,它位于第23层.

productItem.get(1) is just the layerNumber. For this example it's on layer 23.

我收到错误:java.lang.IndexOutOfBoundsException: index=23 count=3

我理解错误:我试图将视图放置在第23个位置具有3个斑点"的布局中.正如您从之前的数字中所看到的,layerNumber并不总是处于1..2..3..4 ...模式.

I understand the error: I'm trying to place a view in a layout that has 3 "spots" at the 23rd spot. As you can see in my numbers from earlier, the layerNumber won't always be in a 1..2..3..4... pattern.

推荐答案

根据此线程.

因此,您可以对layerNumber进行排序,然后以正确的顺序添加子项,也可以使用

So you could sort the layerNumber, and then add the childrens in the correct order, or you could use the addView(view, index) method.

这篇关于在Android中,如何在添加儿童时在FrameLayout中设置其顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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