Custom ScrollView in andengine

风格不统一 提交于 2019-12-20 04:25:15

问题


How can I make a custom ScrollView which moves all the sides. And how do I also find the position where I tapped the ScrollView in andengine?

Thanks in advance.


回答1:


I wrote a small ShapeScrollContainer.java class which is a work in progress but is functional and you are welcome to use,

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

It allows a user to scroll within the container area, contents which you add to the ShapeScrollContainer automatically get moved accordingly. If content is moved outside of the bounds of the ShapeScrollContainer, it will set the content item visibility to false, (as described later you can also get it to fade out the content as it approaches these bounds).

I have included full java doc with explanations for each method. Essentially it extends Rectangle and implements the IScrollDetectorListener, IClickDetectorListener interfaces. Simply add it to your scene as you would another 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);

The OnContentClicked interface method will get called if an item which you added to the ShapeScrollContainer gets clicked by a user. The pShape argument will be a pointer to the Shape which was clicked. The ShapeScrollContainer moves the contents not the camera so any other sprites you have not added to the container will appear unaffected.

You then just call the ShapeScrollContainer.Add() method to add your Sprites, Animated/Tiled Sprites, Rectangles e.t.c. For example, a 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);

Once you have added everything the ShapeScrollContainer has a variety of methods to tailor it to your needs,

//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

Hope this is of use.




回答2:


You can start off of a ClipEntity add a single child Entity to it that holds all the listitems you can translate based on TouchEvents.




回答3:


You can able to create scrollview as your preferable manner.

You have to create one entity as container. In which you have to add as many object as you want. For all these object you have to add touch area enable because you want to select particular item.

And for scrolling you have to implement scroll detector listener and use scroll detector object. Using this listener you get touch distance from x and y which you can use to move your container.

These all things are basic overview which you have to do.



来源:https://stackoverflow.com/questions/16560616/custom-scrollview-in-andengine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!