不同的观点,而不是Stackviews对于Android版本更低至Android 3.0更低、而不是、观点、不同

2023-09-04 12:23:05 作者:风绾梦境悠

我想在我的应用程序中实现 StackView 行为,但我相信这个小部件只能从安卓3.0起。我是一个中间开发商Android操作系统,因此对自定义的视图有限的知识。

I am trying to implement StackView behaviour in my application but I believe this widget is only available from android 3.0 onwards. I am an intermediate developer for android OS and hence have limited knowledge on customized views.

可能有人请提供一些指引,如何我可以在安卓2.2 / 2.3?

Could some one please provide some pointers as to how i can achieve Stackview in android 2.2/2.3?

推荐答案

有与之前的API等级11(3.0)这个确切功能的SDK没有分量,所以你需要创建自己的自定义视图,以获得预期的效果。

There is no component in the SDK with this exact functionality prior to API Level 11 (3.0), so you will need to create your own custom View to get the desired effect.

最简单/最快捷的方法是创建一个扩展的FrameLayout因为的FrameLayout的孩子自动堆叠在彼此的顶部和自定义视图将继承此行为的自定义视图。 您还需要重写孩子们布置的方式,让你调整x和孩子的不同的地方,他们是在栈y位置。

The easiest/quickest way would be to create a custom view that extends FrameLayout since children of a FrameLayout automatically stack on top of each other and your custom view will inherit this behaviour. You'll also want to override the way children are laid out so that you adjust the x and y position of the children depending on where they are in the stack.

您将不得不作出自己的方法去下一个/ previous视图 - 你必须通过重新排序的子视图(它们全部删除,重新添加它们在新的做到这一点顺序)。

You will have to make your own methods to go to the next/previous view - you'd have to do this by re-ordering the the child views (remove them all, then add them back in the new order).

我描述不包括循环来看你与AdapterViews,所以不适合进行大量堆放物品。该解决方案

The solution I've described doesn't include the view recycling you get with AdapterViews, so wouldn't be suitable for a large number of stacked items.

另外,找到StackView源$ C ​​$ C并将其复制到你的项目,尽管这可能还涉及到复制了大量其他Android类到您的项目,因为StackView无疑将进入超类的私有成员只可从窗口小部件包(无反射)。

Alternatively, find the StackView source code and copy it into your project, though this will probably also involve copying a large amount of other Android classes into your project, since StackView will undoubtedly access private members of super-classes that are only accessible from the widgets package (without Reflection).