I'm trying to build a point-and-click adventure for Android without using any pre-written engine, but I'm stuck in a really crucial point!
I have a HorizontalScrollView bigger than the screen, so the user can scroll left and right in portrait mode to search around rooms, now what I need is to insert items that the player can use inside this View.
I'm trying to use static ImageView, but I'm really confused on how to insert Views in an absolute position inside the HorizontalScrollView. All I know is that Android manages Views location relative to other views (align on top, next to, bottom of), but what I use if I need to position a View in a specified position using specific coordinates without worrying that the image will be misplaced in a different screen size for other Android devices?
I really am confused on how position views in Android :/
Consider creating your own view instead of abusing HSV.
Custom views, doDraw() method, canvas and even gesture detection is not that hard.
Here is a link that will help you with basics, simple viewport implementation for android with scrolling via key events: http://sonnygill.net/android/android-viewport/
what I use if I need to position a View in a specified position using specific coordinates without worrying that the image will be misplaced in a different screen size for other Android devices
Actually, that's exactly the reason ViewGroup (layouts) were created.
You should choose the right layout based on your requirements.
If you do want to position the views by yourself, you can create your own custom ViewGroup by extending one of the view group classes and override the onLayout(...) and onMeasure(...) methods which are used to position and measure child views (in you case, probably the ImageViews) respectively.
You can use this example of FlowLayout as a reference on how you can write your own custom ViewGroup.
Please note that if your content is bigger than the screen as you mentioned, the HorizontalScrollView should be a parent of a single child (which should be the ViewGroup containing your images).
Related
I'm looking for a way to display views (like buttons, checkboxes, images etc) in a container, which might be bigger than the actual screen size.
A ScrollView within a HorizontalScrollView is no option, since you're only able to scroll one direction at once, not diagonal.
I have yet to find a simple solution to this problem. A zoom function would be nice to have, but that's not as important as the ability to scroll diagonal.
Are there any components out there able to do things like these? Doesn't even have to be for free.
I have a custom compound view consisting of a textview above an imagebutton (wrapped in LinearLayout). I would like to be able to apply certain gesture-based transformations on it including:
rotating the imageview with two fingers about it's center. TextView stays same orientation
Pinch/zoom to scale the imageview (textview should remain the same size)
move the compound view around the layout
In this scenario there will be several of these views populating a relative/framelayout. The user should be able to interact/modify each view individually.
I've achieved at least a partial implementation for the moving around, based off the answer here: https://stackoverflow.com/a/18806475/2879847. I've read/tried some implementations of the scaling/rotation functions but they seem to apply only to the drawable/bitmap rather than the containing view object so, I'm not sure where to go from there. Any help would be great
Many Thanks - let me know if you guys need any further clarifications.
I've managed to achieve what i want (seems to be working well) - will post some code once my workload dies down.
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.
Is there a way to connect items within a GridView with lines / arrows preferably in the background?
I have a dynamic amount of items (buttons) within a GridView and have to connect certain buttons with others depending on data of a database.
The GridView will most likely be larger than the screen so the view containing the lines/arrows will have to scroll with the GridView simultaneously.
[question]: Android: network relationship graph describes my problem in a more detailed way.
If it were me, I would think to define a layout to be used as the "background" object of your gridview. The layout would be a single relative layout with a custom view that fills parent in both dimensions.
Within this custom view, I would then override the "onDraw" method and all appropriate constructors to perform your arrow drawing on the singular canvas that should be the exact size now of your gridview!
This is where I would think to begin.
Also look here:
Draw background of custom View from .png file on Android
as it shows how to set the backgroundDrawable of a view. If you implement a custom view as drawable, then you should be able to create a new one and send it into your grid view's background drawable.
To make it scroll along with your actual grid data, you may need to play around a bit with the size of the gridview being the full size of the DataSet you are displaying, and containing that within other scrollviews to get this accomplished.
I do have a gridview in an app of mine, that I implemented a horizontal scrollview (as I have buttons at the top allowing me to sort by any of the columns and want those always to be visible, and the gridview to vertically scroll underneath). This creates the overall width of the gridview for me as it simply follows the parent width which wraps the content of the linear layout defining the button set at the top. The gridview then auto scrolls in the vertical direction, leaving the higher level horizontal scroller to perform in the horizontal direction. For you, you may need to have a vertical scroller within a horizontal scroller, and allow your gridview to be full size (i.e. larger than the content view area) and allow the outer scrollers to perform the scrolling for you. This may be the only way to ensure that your background drawable view is the proper size to the table you are trying to display!!!
i have built a custom viewgroup and m beginning to implement animations tot his viewgroup. the problem i am having is that i need the viewgroup to be able to animate without it's children being animated by the same animation.
Lets say i am scaling the viewgroup to 2x size, but i still want to keep children at the same size (thus fitting more children into the viewgroup).
Right now i am calling the animation as follows:
ScaleAnimation expandAnimation = new ScaleAnimation(1,2,1,2);
this.startAnimation(expandAnimation);
Thanks in advance! :)
You can't directly do what you're seeking to do with the old Android animation API. You've already noticed one limitation - that scaling the group also includes the children.
The second limitation is that the old Android animation API only affects the visual render of the item you're animating, and only for the time the animation is active. In other words, it doesn't actually alter the size or positioning of the item in question in terms of view layout. It only temporarily renders it a different way. So for instance, to animate a button moving from x to y across the screen, you would need to run the animation, then when the animation completes actually reposition the button using the layout APIs.
Probably the way to do what you're looking for is:
Incorporate an extra ViewGroup
widget in your layout, positioned
and sized over top the widget
containing the "real" items.
Initially, it's invisible.
Make
it visible, and play the animation.
When animation complete, hide the
extra widget, then resize your real
ViewGroup widget via LayoutParams
and add your extra items.
You'll
probably need to tweak this general
outline to make the effect look
smooth. (For instance, resize the real viewgroup in the background before you remove the fake viewgroup from the screen).
Android introduced a newer, more flexible animation API in 3.0 Honeycomb, but unfortunately it's not available if you're targeting 2.x devices (i.e., phones). Hopefully this will be easier once the new APIs are mainstream.