Is it possible to draw an image over another view (like a button) and still have the view work normally? The user would still be able to click on the button even though there is another image on top of it. I want to draw some mostly transparent pngs over my layout for lighting effects, but I want to make sure everything will still work correctly.
Try using a RelativeLayout with an ImageView on top of the widget(s) in your app. See this question for a quick example.
Related
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".
I am searching for it from very long time. I want to blur the background of the new added view to the frame layout. The new added view is a linear layout which opens as a pop up. Now how can I blur that frame layout.
I have gone through all the posts regarding blurring the background but i did not find that useful for my problem Because they all suggest to create a bitmap and set it blur on the bitmap. I simply want to blur the complete view behind the pop up
Use this library to blur the background of popup https://github.com/faradaj/BlurBehind
On BlurredActivity show the popup and finish the activity when pop dismiss.
You can use Renderscript Intrinsics, which are a set of built-in functions that require very little code to use, but are optimized for high-performance.
Once you have the blurring, the rest of the process is fairly straight forward. When you plan to leave an activity, create a bitmap of the current view and write it to disk. When you start your new activity (which should have a transparent background), you override the transition (otherwise you’ll get the default zoom), and set the background to the blurred image you saved earlier. Add a fade in for the alpha and you get a nice little effect!
If you’d like to see how this looks in a sample project, you can find it on Github here.
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 would have thought that there would be a variety of options in connection with a button's background from an image, for example the image could be tiled, or stretched or centred etc etc, but when I list a button's methods I can't see anything. Now I'm suspecting that it could be a two stage process, perhaps getting some kind of view first and then using a method of that view. Or maybe there is simply no control whatsoever concerning a button background. Please advise.
Note that any View's background is something that fills the area covered by that View, so you can't have it centered.
Stretching the the default behaviour, that's why a state list of 9-patches the the best thing to use for Button's background.
If you want tiled background, you may use XML Bitmap with tileMode="repeat". See also other kinds of Drawables on this site. You can for example make something that feels like centered background image using Inset Drawable.
And finally the functions are there: setBackgroundDrawable and setBackgroundResource.
Is there a way to draw ontop of every view (like a watermark that shows everywhere for example)? sort of how the Dock4Droid app draws a a dockbar ontop of every screen.
Your best bet is to have a relative layout as your top level container. The very last item in your markup should be an imageview containing your watermark which you can then position on the screen anywhere you like.
As an alternative, you can do your own drawing (onDraw) and set the opacity value such that it gives the presentation of being translucent. Works for me with several of my requirements.
I don't think this is possible, as android app drawing is effectively sandboxed.
Even if you could, why would you want to? It seems like a major annoyance for your users. I know I would uninstall an app that did that.