Android: strecthing background - android

I want to have a gradient on my app background. The picture is only ten pixels wide and I would like it to repeat horizontally. Then I have the background set to the color where the gradient ends vertically. In CSS I could easily do this by this code:
background: url("bg.png") repeat-x #0f0f0f;
But I have no idea how to do this on android. I tried setting a bitmap but everytime I put it in the XML the app force closes on me and there doesn't seem to be "repeat-x" like option on it.
So what would be the best way to handle this?

you can use bitmap shader to repeat a particular bitmap .
Refer to this link
Also check this Api Demo Example

Related

Image processing, replace picture background or cut out picture background

In an Android app, I would like that the user choose or take a picture of him from / with his device and then replace the background by another one (for example an awesome beach).
I'm looking for a library that can cut out the original picture background (the original background can be a color or maybe a landscape). Or maybe a library that can give me some tools to draw the part of the picture to keep / remove.
If a such library does not exist, I think that the "pixel replacement" method is the best way if the original picture has a color background (for example, I look for all the black pixel and change them with a transparent pixel).
I have found this tutorial but as you can see the result is not perfect. Is there a way to do not check only one color but a range of colors ? Is there a way to define programmatically the range of colors to check ?
Thank you in advance for your tips and links !

How to replicate iOS 7 Blur View in Android

I like the style iOS 7 has used for their Notification and Music popover like below.
So, I try to implement this thing in Android. After doing some search, I achieved how to do that. What I have tried is following.
1) First I take a root reference of the View and take a snap of it using getDrawingCache() function of View.
linearLayout.buildDrawingCache();
SoftReference<Bitmap> bitmap = new SoftReference<Bitmap>(
Bitmap.createBitmap(linearLayout.getDrawingCache()));
linearLayout.destroyDrawingCache();
2) I take the position relative to its parent and cut the image as per requirement.
SoftReference<Bitmap> temp = new SoftReference<Bitmap>(
Bitmap.createBitmap(bitmap.get(), 0,
(parentHeight - childHeight), childWidth, childHeight));
3) I make that bitmap image blur with some algorithm. ( I use Fast Bitmap Blur For Android SDK fastBlur effect )
4) set it in the overlay view.
imageView1.setImageBitmap(Utils.fastblur(temp.get(), 8));
But my problem is it takes time to take a snap then giving blur effect and cutting image and then i got final result. While iOS has very fast blurring process like when drawer is coming from bottom, it immediately blur the screen which is behind it.
Is there any other way to achieve that? Because using my scenario, i can't take every second snap of screen and do all process 1 to 4 every second on every move of drawer.
http://nicolaspomepuy.fr/blur-effect-for-android-design/
I don't know if you have seen this link, but check it out. It talks about how blur effects can be achieved in around 200ms.
PS: check out the comments as well !
Ok so if I understand your problem correctly is that is you have a drawer mechanisme that you need to update the blurred image every pixel the drawer has moved?
Then the solution to your problem would be to blur the screen one time and use this image together with some fancy algorithm to show/hide and position that image so that it seems that the drawer will blur instantly but in actually what's happening is that the image was already generated.
You just show more or less of the image to create the effect.
Don't know if I'm making sense or if I even understand your question.

Where are the options to control a Button's background?

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.

Create a foggy effect on screen

Is it possible to create a fog effect on the screen of an android phone. iFoggy was able to get this effect (see picture) for an iPhone.
Is it possible to achieve the same for an android app. I just want the foggy effect and don't want anything to happen when the user touches the screen.
I'm guessing this might be achieved using Bitmap but I've never used that before so any tips would be helpful.
you can have a look at this question here to have Blur Effect for your screen
Make a transparent activity. Refer this answer. click
And set the background for the layout of this activity, a transparent PNG file. Here is the PNG file.
click

Draw a gradient filled polygon to use in a selector

I am trying to create a drawable such as this in Android:
I don't think a nine patch will work because there is nowhere that can safety scale vertically. So next I tried a shape drawable but it does not support triangles.
I want to render this image on the fly so there are no artifacts. Also I want to be able to use it in a selector, so I need to be able to represent this image in xml. Maybe I need to extend some class to manually make the shape. If so how do I embed a tag in the xml to tell it where to render? Does anyone know where to start with this or have an example of something similar?
I have read the first 10 pages of hits on stack overflow and google and am not getting anywhere. Thanks very much for any help.
I think a 9-patch would work. For the vertical stretching on the left boundary, fill in the line from top to bottom.

Categories

Resources