Full-screen gallery scrolling problems - android

I'm building an app based on a card game. A user may look at his own cards; he can also scroll "around the table" to look at the open cards of his opponents. The screen shows one player (the user or one of the opponents) at a time.
I used Gallery to implement it. With a custom adapter, I made it circular. I have also intercepted onFling() to make sure it "flings" to the next player, not further around the table. So far, so good.
Here is the problem. If the element of the gallery is as wide as the entire screen, gallery does not work well. I can't drag the view "slightly" to expose the next player. Most of the time, the fling does not work. When it does, there is no animation; the view just switches to the next player.
I solved it by making gallery elements 2 pixels narrower than the screen. 1 pixel is not enough: it fixes scrolling in one direction, but the other direction is still "stiff".
I'm writing this for two reasons. First, if you have similar problems, this post may save you a few hours. Second, I'm curious: can any of the Android gurus explain this behavior of the Gallery control???

I did the same kind of stuff but with a HorizontalScrollView. Maybe you should try with this instead of a Gallery.
You just have to set an OnTouchListener on the view and adjust the scroll when the onTouch catch an MotionEvent.ACTION_UP.

Related

Is it possible to host (or mimicking hosting) of views withing live wallpaper?

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) ?

Android: Update ImageView Background while Behind other ImageView

I'm building an app where I want to swipe images as though they were photos on a stack. In other words, if I swipe the top image I want it to animate moving in the direction of the swipe and have the next image underneath it visible the whole time. To accomplish this, I'm using a FrameLayout and two ImageView containers. I'm just alternating which one is on top. Meanwhile, as soon as a swipe occurs, the next image is loaded into the ImageView at the back using setBackground(drawable). My problem is that the ImageView at the back doesn't update it's image until I call bringToFront() on it, which means that as the top ImageView is animating, the image underneath is incorrect until the animation completes, at which point it abruptly changes to the correct image. I've tried calling invalidate() on the rear ImageView after setBackground(drawable) but this doesn't work. Anyone have any ideas on how I can get the image to update while it's behind?
UPDATE: Turns out I'm just not very on it today. I was updating the wrong ImageView and because the image loading was being done off the network, there was just enough lag to make me think it was happening after the animation completed.
Sounds to me like you wanna do something like an Image Slider.
There are great libraries existing for this purpose, this one for example:
https://github.com/daimajia/AndroidImageSlider
If you don't wanna use this, here are some tips:
Images on ImageViews are set with setImageDrawable(Drawable)
When your animation starts, set the new Image to your ImageView behind and slide the visible one away.
When the visible ImageViewhas slided away, set it's visibility to GONEand move it behind the second ImageView
Do this for every time a new image is loaded.
This should actually work.
You need a "ViewPager"
https://developer.android.com/training/animation/screen-slide.html
It has all the necessary handles to accommodate "N" number of images - also supports multiple swipe animations - default handlers - efficient memory management - prefetching - you are all in for a feast with this !!
Just make sure you get the "ImageView" in the layout of the "pages" you wish to develop on the "ViewPager".

make main view of app larger than the phone's screen

working on an app and The way I want to set it up is different than what I have ever done before. I want the main activity when launched into the app to exceed past the boundaries of the physical phone screen, and for the user to be able to swipe out to parts of the app that they can't originally see.
I am not sure what the terminology is or what methods or classes etc to use. Any info that could point me in the right direction would be great! Thanks!
Just some clarification:
I think what I'm trying to say is the second thing you talked about. Imagine if you place a iPhone for example in the middle of a piece of computer paper. What I want to achieve is to have the whole view the size of the paper, but only be able to see the size of the iPhone's screen at a time. So you can go up a little bit and see what was above the screen, or left or right
If you want more screens and be able to switch between them, use ViewPager.
If you want one large view bigger than screen, you can either combine ScrollView for vertical scrolling and HorizontalScrollView for horizontal scrolling, or make some custom View, which will be able to scroll (you have to implement it on your own) in both direction.
If you want to have just some views outside of the screen and bring them to visible area on some event, you can use RelativeLayout and set to its views proper margin.
If you want something else, add more information, how it should look and act like.

How did they make such layout - which elements they used?

At the moment, I am using Euro 2012 app and it has some interesting layout parts. If you go to matches->knockout screen, you'll see 3 screens like this.
If you slide left or right, you move between them not like between one activity to another, but just like all these elements are laid on one big canvas and you slide each screen into focus. Even thou, if you slide left/right, the screen cannot be stopped in the way that half of each image is visible, so I guess it's not a big canvas. Somehow you can slide screen like one big image, and yet it always lock perfectly as if they used 3 activities for this.
How did the do this?
It's a ViewPager, available in Android support package and described in their blog.
The designing is not so much difficult, As i think to draw that boxes showing quarterfinals, semifinals.
They having layout( we can do by placing image in background also).
The major role played by FrameLayout which shows you that effect(emphasis), the flages are fetch from url as matches are decided(not essentially images only names are sufficient as flags came inside app and gets applied as updated).
After your click i think the start image gets change it's just replacing that image with new one.
As you said they are not on single canvas (but if they did customization of heir Viewpager that it's not stopping in between activities), but i think it's on single canvas.
If your taking about quickness of loading and all it's up to you as much code and processing you optimized it gives you smooth feel and fast processing.
We can appreciate the work but we can not say it's too much difficult as i think it's quit easy...
Hope this explanation helps you to understand ....

Android TranslateAnimation after scrollTo() = undrawn view

This might be a "duh" question but I'm going to go ahead and ask it anyway.
I have an oversized (bigger than the screen) RelativeLayout, and I'm using swipes to start a TranslateAnimation from viewing one part of the layout to another. Say for instance the layout is two screen wide and two screens tall. After the nice animation to shift the screen, I was using View.scrollTo() to set the new position. This works fine going from the first screen (top left at 0,0) to one of the others. When I swipe to animate back to the first screen though, because the View.scrollTo() invalidated that part of the layout (I assume), that part of the layout is all black as I animate through it. I tried a couple things to get it to redraw itself after the scrollTo() but haven't had any luck, so I figured I'd ask here.
thanks!
joe d
I can't help with your specific problem since I've never tried working with a layout bigger than the screen, but there might be another way to achieve what you're trying to do. If you simply want to be able to finger-swipe from one View to another, without ever displaying part of one screen and part of another (i.e. you aren't smoothly panning around a large View but rather just jumping from one distinct section of the layout to another), then these tutorials might help, here and here. They show you how to use touch events and the ViewFlipper widget to change between Views using animations.

Categories

Resources