i have to take something like a screenshot in my android application. It is not a screenshot, it should be a "viewshot". It is about to render the complete content view on a bitmap.
I have found the solution to render the content view of the activity on a bitmap, but if the content view is bigger than the activity, it is only the visible part which gets drawn onto the bitmap.
Does anybody have a solution for this, or some ideas what to google?
Thanks
The content view is never "bigger than the activity", by definition.
The content view may be scrollable, but most scrollable things are either AdapterViews or use a tile mechanism (e.g., MapView), none of which are rendered until they are scrolled into a visible position. There is no stock way to make a "viewshot" of things that have not been rendered. You are welcome to create your own AdapterViewShotter that iterates over the items in the Adapter, captures each to a Canvas, and stitches the lot together into a huge image.
Related
background
I've made a simple app called "LWP+", which shows a cropped image . When the user chooses a photo, I save it into a file, and then do the cropping when needed. I do this by using 2 libraries. One for allowing the user to choose the cropping rectangle, and one for the actual cropping.
The problem
This is just for a normal cropping, but a nicer feature I'd like to add is a way to scroll through the content of the entire given image, at least horizontally.
On a normal Activity, I'd probably use a ViewPager that has an ImageView for each page.
But here a live wallpaper doesn't really have a layout.
What I've found
There isn't much of information about live wallpapers in general, but when I've searched for scrolling of an image in it, I've found just how to move the canvas.
This can actually be a good idea, of somehow having bitmaps (or partial decoding of the image) around the current position, and translating the canvas as needed. I could also use a GestureDetector class to identify flinging, but this is only a tiny fraction of what's needed to do a nice scrolling of a zoomed image.
It is also very complex, as it requires good memory considerations in mind.
If I could use a normal view, I could have used a ViewPager, or even a third library that shows an image and allows to scroll in it freely , like in the gallery app (such as this one).
The question
Given a View of any kind, such as ViewPager or another, is it possible to host it somehow inside the LiveWallpaper, to let it show content, and to handle touch events ?
Alternatively, is there an efficient way to view content as I've written, yet in a live wallpaper? Meaning viewing a portion of a large image, while allowing to scroll though it (like a ViewPager, but maybe even freely like on a photo viewer library, in all directions) ?
I got a SurfaceView, in which I display a bitmap that is much larger than the actual area of the SurfaceView, so I have implemented a way for the user to slide their finger on the bitmap and move it up and down. When doing so, I would like to be able to display a vertical scroll bar, preferably the standard Android scroll bars, instead of drawing something custom.
The thing is, I would like my SurfaceView to stay the size of the screen, that is I don't want to scroll the SurfaceView itself, I just want to create the illusion that the user is scrolling the contents, and therefore display the scrollbars.
I tried setting android:scrollbars = "vertical" in the layout's XML, I tried mSurfaceView.setVerticalScrollBarEnabled(true); and I tried awakenScrollBars(); whenever the user touches the SurfaceView, however none of those displays the scrollbars.
So, is it possible to display the standard Android scrollbar on a SurfaceView?
short answer is: no!
everything that the SurfaceView ever draws on the screen is whatever you directly call to be drawn using the whole lockCanvas and unlockCanvasAndPost that you know about.
Putting those parameters in the XML make it possible for you to read them in Java via the AttributeSet in the constructor, but that's only for configuration, it won't drawn anything.
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).
I'd like to create something like a carousel with views. A continuum queue with an indetermined amount of the same type of view (just like a list), but when swiping left/right, (or up/down) it would move to the next/previous view (I could be cool if it did that with an animation, too). Plus, I also need to move though it by buttons. For example, "move to view 20".
Could you give me an advice on what to use for my purpose? Thanks in advance
Edit: By the way, grey big thing in the picture represents the current view, while the other thinner rectangles are the preceding and following view.
Please take a look on this answer Android page control like book?
You can make gaps between pages with setting margins or padding.
I have a custom view that is scaling to 200% when the user clicks on it.
Now I want to prevent some controls/views in that custom view from beeing scaled.
Is there some way to do this?
After further investigating I think there is no way to programmatically freeze a view as described. As a dirty workaround you can put the view that should not be scaled in another container that is positioned over the scaled view.