Essentially what I want to happen is, after the user scrolls the list, I want the elements to snap into 'grids' instead of remaining where they are, so that I can center the middle component in the list, like in the picture.
I tried manually changing the setSelectedIndex after setting ScrollToSelected to true, but that lacks any animation, and the list scrolls the element to the edge of the screen, rather than the middle.
How can I have the effect of scrolling the element with animation, and to the middle of the screen?
LWUIT & Codename One both have a snap to grid property in Container and in List. Did you activate it? Just use setSnapToGrid(true) on any component.
Related
I have a RecyclerView in which I add items regularly. I want the background of the RecyclerView to expand while the list of items grows.
For example, if the list has two items and a new one is added, a new part of the background is discovered, and so on...
What I expect
The complete RecyclerView is as in the image below. The user can only see a part of it, but discovers the rest when he/she scrolls up or down (which is why RecyclerView exists, I believe).
Here we can see that the whole background is actually expanding beyond the screen's top and bottom border. So whenever the user scrolls the RecyclerView, the background moves with it (matching the movements of the list).
I'm completely lost with that, do you have any idea how to achieve such a behavior?
I need a widget that functions as a horizontal scrollview, but snaps to the nearest value when scrolled (it should snap from value to value, and not be possible to stop the scrolling in between values). Theoretically I would solve this with a viewpager with negative margins - so that all the views are simultaneously visible, but it also "snaps". But I have a problem - if I use a viewpager then only the "foreground" (i.e. currentView) view is "clickable", and I need all onscreen visible views to be clickable at any given time. So - is there any way of having a "snapping" horizontal scroll widget where all visible views are clickable?
For example, the screen might look like this:
A B C D E
where scrolling right reveals F, G, H..
initial state should allow clicking on any of A,B,C,D,E and not just on A (if it was the "currentview")
You can use Snap ScrollView library. It supports both horizontal and vertical snap scrolling. You can add views directly. Click on this SnapScrollView library
And regarding click, you can implement onClick listener for each view and call correspondingly.
I have a tree with number of childs and i want to drag and drop these child items on a vertical panel. Right now its working fine.The only thing i want to know is can we add an image in the place of small icon which comes at the time of dragNdrop.
You need to override the newDragProxy() method of the PickupDragController in order to provide your own proxy widget (say, an image) when the drag starts.
Do note that you also need to use setBehaviorDragProxy(true) to allow dragging proxies instead of the original widgets (i.e., the original widgets will stay in place, and you simply drag a proxy of it, that you can style as you wish).
On my page I have a panel which is hidden by default. I can show it via myPanel.setVisible(true) when necessary. After this the height of the window is increased and the window scrollbar appears.
The problem is that the window is not scrolled to the bottom automatically, which is a desired behaviour. How can I fix it? I just want to scroll my page to the bottom.
I know Window.scrollTo (LEFT, TOP) can help me. But the problem is that I dont know how can I calculate the height of the page relative to the top - the second parameter I need to provide to this method. I really tried numerous ways:
Window.getClientHeight();
Document.get().getScrollHeight();
Document.get().getBody().getOffsetHeight();
Document.get().getBody().getAbsoluteBottom();
First two of them do not change their value after the hidden panel becomes visible. The second pair gives me 0 and 8 (???) values.
So how can I solve my issue?
ps
If the situation is a bit different and I have a div with a scrollbars, not the window scrollbars, is it possible to scroll it to the bottom programmatically?
You can use setVerticalScrollPostion API and set the position of the scroll
Is it simple Panel or some subclass of it.
In any case, try first with:
int top = myPanel.getAbsoluteTop();
and then scroll to some value aggregated with top.
From API:
public int getAbsoluteTop()
Gets the object's absolute top position in pixels, as measured from the browser window's client area.
For scrolling down the document, you should use the scrollTo method in Window object, i.e.:
Window.scrollTo(0, Window.getScrollTop() + Window.getClientHeight());
You actually do not need to know the size of the page to scroll to it's bottom. Just use
Window.scrollTo(0, Integer.MAX_VALUE);
At least this always worked for me.
If you want , you can create a widget handle with an id.
For example : widget.getElement().setId("scrollPanel");
Then you can scroll the view on the widget with Document.get().getElementById("scrollPanelFooter").scrollIntoView();
It's simpler!
In windows, Java, etc, the scroll pane scrolls the widgets inside. What I'm wondering is, how exactly does it do its scrolling? Does it change the location of each nested widget, or does it have a content widget that it moves around? Or is it something else? Also, when both scrollbars are present, how does it mask that little square at the bottom right? That square is sometimes used to resize. Is it a separate nested widget?
Thanks
I think it just changes the location of the widget, button, or thing-a-ma-bober.
But my second guess would be it just draws the components "outside" of the scroll pane without being seen and when you scroll it just redraws dynamically.