Android drag and drop, endless layout - android

I want a screen to arrange rectangles with drag & drop. Elements can be moved freely, so it's not a grid or list. I think I should use absolute positions.
My main problem is that I need an endless screen (when drag to right, scroll the screen to the right). One solution I found was to set width and height to 10000dp and a 2d scroll. Another way is to resize the container each time the user drags an element.
I need a better solution if possible. Any suggestions?

Resize the container each time the user drags an element out of the current view bounds should be the most performant idea.
By the way you should put some max size limit to the view, otherwise you will run out of RAM fast and your app will crash.

Related

Drag and drop in long layouts

I can't finish the design of my page. I have a relative layout inside a linear layout inside a scrollview. My relative layout has a max width of 800, the drag and drop feature can only see the size of the current device screen size you are using.
How can I view the area below it? I can't get this app done, I'm still getting around on how to use the android studio IDE. I've just been guessing the alignment manually through the xml file and I just wasted 4 hours.
This is just for aligning the elements properly. But I can't do it if I can't see it.
ScrollView class holds some API to allow you to scroll based on a given offset.
If you can calculate when the touch event has reached the limit of your view ( I imagine it would be the bottom or top edge of your screen, but I guess it does not restrict to this ) you can tell your scrollView to scroll a bit.
I've thrown out a few quick tests and found some troubles caused by event delegates (like, ScrollView touch event is bad handled and interrupted when the dragNDrop event handler of the views kicks in, or the other way around). Haven't tested this, but having a top level transparent clickthrough layout could help in some cases, but that's just an un-tested idea

recycling views in scroll view

I have an app that show the tv guide for a list of channels. My UI is made from a a lot of custom views with different widths that show the tv programs, all these custom views are added into a horizontal scrollview that is added into a scrollview so my views can be scroll in 2 dimensions left-right and top-down. It all works good until i add add a lot of views and it starts to slow down very much. So i need a way to recycle views like listiew does in a scrollview maybe there is a custom made scrollview that does this, or someone has an idea how to do this, its strange that scrollview isnt backed up by an adapter like gridview and listview.
I did something similar only my Views were not connected as yours but they were all different sizes.
First you need to define if your entire area (not just viewing screen) has definitive or dynamical number of your custom views.
If you have definitive number of views and their positions you should create their position map with list of Rect's (Rect has a good function whether the xy point belongs). Then you define maximum of Views which are visible on your screen. For this to work without constant loading you should have maximum visible views + at least one line of border views of total objects. After all this you should easily have your own positioning system where you load views which are in bounds of your screen + some overhead (purpose of this is that you want your users to have smooth transition while scrolling at least for some length), if you need to load some in same time you unload (read reuse/ do not dispose objects and create them onScroll events) and place them according to your needs.
And if you want to determine which views should be visible you just go through list and ask whether Views Rect intersects with your Rect of area to be loaded.
Hope this image helps a little bit more
I know it sounds a little bit confusing and difficult to implement but you did not asked a simple question :)
Hope this helps and enjoy your work.
A ScrollView that is backed up by an adapter and recycles views is a ListView, with a couple of extra optional features on top.
Maybe you want a HorizontalScrollView that is backed by an adapter? Searching for HorizontalListView will give you a few results, ex: https://github.com/dinocore1/DevsmartLib-Android.

Partially hide Layout programmatically?

What should I do to partially hide some layout from code? Should I play with setMargins?
Basically, I want to detect size of the screen and then I want that element X becomes visible only 10% of its width? I know how to do it all except how to make it partially hidden or offscreen?
Look at these images to see what I want to achieve. Image 1 - UI element is in the center. Image 2 - I set in code it's moved to top offscreen thus becoming only partially visible.
I found out that here as well the best solution is to use Animation (TranslateAnimation) by setting this on the first screen load and setting its speed to minimum value of 1 millisecond. The transition in reality is unnoticeable to a human eye.
Also do not use margins as they simply "push" element from one side without making it goes offset. If you have any child in the layout you want to offset, they all will be squeezed as you increase margin values.
NOTE: if you ever want to use animation on that screen on the element you offset before, take into account the negative value of offset. Otherwise your animation will not look nice. To avoid bumping effect, take special care of fromXDelta value.

large, long images scrolling across screen at different speeds, and off of the left of the screen

So I have multiple very long images (like 2000x100) that i want to have scrolling across the screen at different speeds. and my original solution is not working out. Originally, I placed them all in a HorizontalScrollView, and made a runnable that used setPadding to adjust the position of the ImageViews within the scrollView. This works, however, the background that is supposed to remain mostly stationary on the screen, shakes back and forth as you scroll, and lags behind the scroll location significantly. It's choppy and it looks bad.
Is there any other way that I can move images across the screen to achieve the desired effect?
(could I perhaps use a frame layout, and set an ontouchlistener? then how would you move the layout across the screen?)
I set up a layout so that the images protrude off of the right of the screen correctly, but I can't seem to move them off of the left of the screen (setpadding(-50,0,0,0) does not work)
Thanks in advance!
I solved this by using relative layouts within a frame layout. I set an ontouchlistener for the frame layout and used the scrollTo method for each image with a modifying coefficient. I had not previously noticed the scrollTo and scrollBy methods of the layout.

Android ScrollView: Automatically scroll to a few pixels (dips) above a certain view

I am aware that I should decide how many pixels based on density.. not hard coded.
I have section headers and items displayed in a scrollview and I want to scroll to a certain section header (the one for the current date) while making it clear that it is not the top of the screen (show about half of the previous item).
How can I do that? I do not want this automatic scroll to be animated.
With View.requestRectangleOnScreen() you can scroll to show a particular rectangle (the linked method allows disabling animation). You still will have to calculate that rectangle, but once you have the position of the particular child (your header) you can easily do that getting the size of the ScrollView. You could consider the small offset you want in calculating that rectangle or just do a scrollBy() after requestRec....() (the former way is better I think).
An easy way to use a density independent dimension is to define it in xml as a dimension resource.
-- edit: you get the position of the child in parent with getLeft() / getTop().

Categories

Resources