编程语言
首页 > 编程语言> > java-andengine中的自定义ScrollView

java-andengine中的自定义ScrollView

作者:互联网

如何制作可移动所有侧面的自定义ScrollView.以及如何在andengine中找到ScrollView的位置?

提前致谢.

解决方法:

我写了一个小的ShapeScrollContainer.java类,该类正在进行中,但是可以正常使用,欢迎您使用,

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

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

我提供了完整的Java文档,其中包含每种方法的说明.本质上,它扩展了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()方法即可添加您的Sprites,动画/平铺Sprite,Rectangles等.例如,一个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

希望这是有用的.

标签:andengine,android,java
来源: https://codeday.me/bug/20191013/1906500.html