在andengine中自定义ScrollView

如何制作一个可以移动所有边的自定义ScrollView 。 我如何找到我在andengine点击ScrollView的andengine

提前致谢。

我写了一个小的ShapeScrollContainer.java类,这是一个正在进行的工作,但function正常,欢迎您使用,

https://skydrive.live.com/redir?resid=EB5E1E510A150D4D!105

它允许用户在容器区域内滚动,添加到ShapeScrollContainer的内容会自动相应地移动。 如果将内容移动到ShapeScrollContainer的边界之外,则会将内容项可见性设置为false(如稍后所述,您也可以在内容接近这些边界时淡出内容)。

我已经包含了完整的java doc以及每种方法的解释。 本质上,它扩展了Rectangle并实现了IScrollDetectorListener,IClickDetectorListener接口。 只需将其添加到场景中,就像另一个Shape一样,

 ShapeScrollContainer ScrollableArea = new ShapeScrollContainer(x, y, width, height, new IShapeScrollContainerTouchListener() { @Override public void OnContentClicked(Shape pShape) { // TODO Auto-generated method stub } }); mScene.registerTouchArea(ScrollableArea); mScene.attachChild(ScrollableArea); 

如果您添加到ShapeScrollContainer的项被用户单击,则将调用OnContentClicked接口方法。 pShape参数将是一个指向被点击的Shape的指针。 ShapeScrollContainer移动内容而不是相机,因此您未添加到容器中的任何其他精灵都不会受到影响。

然后,您只需调用ShapeScrollContainer.Add()方法来添加您的精灵,动画/平铺精灵,矩形等,例如,一个ChangeableText,

 final ChangeableText mMessage = new ChangeableText(x, y, mFont, "Scroll Me", HorizontalAlign.LEFT, 14); mMessage.setVisible(true); mMessage.setZIndex(10); mMessage.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); mScene.attachChild(mMessage); ScrollableArea.Add(mMessage); 

一旦你添加了所有东西,ShapeScrollContainer有各种方法来根据你的需要定制它,

 //Whether you want to allow user to scroll vertical/horizontal ScrollableArea.SetScrollableDirections(false, true); //Only allow the user to scroll in a direction to available content //(no more content in that direction - the user will be prevented from scrolling) ScrollableArea.SetScrollLock(true); //By how much over the last content in any direction the user is allowed to scroll (% of height/width) ScrollableArea.SetAlphaPadding(10.0f, 0); //Allow ShapeScrollContainer to increase alpha of contents and by what distance it starts inside //the ShapeScrollContainer itself. (Fades content as it approaches the edges due to user scrolling) ScrollableArea.SetScrollLockPadding(50.0f,0.0f); //Whether scroll bars will be visible, (horizontal/vertical) ScrollableArea.SetScrollBarVisibitlity(true,true) //... //A lot more methods to refine the ScrollableArea appearence and behaviour - see java doc 

希望这是有用的。

你可以从ClipEntity开始向它添加一个子实体 ,它包含你可以根据TouchEvent转换的所有TouchEvent

您可以创建scrollview作为您的首选方式。

您必须创建一个实体作为容器。 您必须在其中添加任意数量的对象。 对于所有这些对象,您必须添加触摸区域启用,因为您要选择特定项目。

对于滚动,您必须实现滚动检测器侦听器并使用滚动检测器对象。 使用此侦听器可以获得距x和y的触摸距离,您可以使用它来移动容器。

这些都是您必须要做的基本概述。