I have 5 images background, i want bg can randomly to shown, included horizontal and Vertical,i need to prepare 4 set (iphone&pad) X 5 images = 20 images for each OS? Android also need to prepare 4 X 5 set. is it right? Except this way, still have another method?
If follow above method, the file size at least have 40MB.
Is this background image texture based or of a repeating pattern? In that case, you can use a Nine-Patch image for the Android app, thus resulting in smaller size (still need to provide for different dpis).
For iOS, probably something on the same lines as given here:
Repeating background image in native iPhone app
Few more links that can be of help for this scenario:
http://useyourloaf.com/blog/2011/08/22/using-pattern-images-to-set-background-views.html
http://kylewbanks.com/blog/Android-iOS-Repeating-Background-Image
Related
I am developing an app for android, in this app there are 30 pictures that need to be stretched for multiple screen resolution. every 10 of them have exactly the same 9-patch borders.
So here we can specify it for only 1 picture,
but I have 10 pictures with exactly same sizes, but different colors.
Is there any solution to work on 10 pictures at the same time ? because they already will have the same 9-patch.
i'm guessing you just want to save yourself the work of applying the 9patch another 9 times. you sure could automate that, but i doubt it's worth the time if it's really an one-time job.
if this is recurring work, i'd write two small cmdline tools:
Script A: extract the 9patch-part from a png (just copy the outermost lines) and save it to a file
Script B: 9patch-part file and apply it to an existing png file
let them work with parameters so they can be scripted easily.
it'd be easy in java and you already know the language. estimated time for both: around 30 mins to an hour.
remember: "9-patches" are nothing else than a 1 pixel border in a completely normal PNG image file where the color is either transparent (do not scale) or black (do scale).
I want to build a digital clock widget for Android, and I have written the numbers from 1 to 10 on paper and scanned them, so that I now have the numbers as per images with transparent background. I may have missed it but I can't really see if in the documentation anything about using images as numbers. Would i be better off creating a font even though it would only consist of the numbers?
First off: add each image separately to the res/drawable directory and reference them from there.
An Opengl surface could render them or, more easily I think, an ImageView with programmatic image flipping.
I'm working on the same thing. Any idea how to run an onTick()-like function for currentTimeMillis()? That would be the path to victory on when to render the next second on your clock face.
I need some help,
I am creating an app, and want it to run faster I mean when the app is started first it shows a blank white screen for o 1-2 seconds and then loads images. I have a layout background image, and 4 imageviews which are clickable and take you to the next activity. I read somewhere i should use threads to load images and it will load them on a separate thread faster, but i have some problem using it.
So here are the problems and android studio explanations:
Thread thread=new Thread(
public void run(){
ImageView tipka=(ImageView)findViewById(R.id.tipkaproba);
tipka.setImageResource(R.drawable.instructions);
LinearLayout asd=(LinearLayout)findViewById(R.id.layoutproba);
asd.setBackgroundResource(R.drawable.backfround123);
}
).start();
Now the android studio says:
After
"Thread(" )expected
Before
"public void run(){"
; expected
On ").start();"
Invalid method declaration; return type required, Missing method body, or declare abstract.
Now i would like to know:
Does this speed up loading images, ( if not how to do it then)
How to fix my errors.
Thanks anyway !
Do all images fit in the screen?! If users need to scroll to view other images why load all of them at once? Use a grid view with adapter to load the image. In this way when the app start only images on the screen will be loaded and then when the user scrolls other images show up!
another thing you can do is to have 2 version of each image. one low quality with small size that loads first and one for high quality image. that will load latter. You can also calculate the base color for each image (use open source code or do it manually). then set the background image of iamgeview to this color. So when the image finally loads on the screen. The difference is not as dramatic as it was before.
If you want to use thread try AsyncTask first. Using AsyncTask is simpler than defining thread yourself.
Try to decrease the size of your images! If you be able to do this. it works better than any other trick! It's mobile, you don't have to show supper high quality images. users don't even notice most of the time
You probably took care of this but it worth mentioning that you need to provide different images for different screen densities and it's critical for performance as well as quality.
Actually I have for so long wish to know how to present graphics in a proper way.
In an activity, I have the following:
a background (png, full screen, 768*1280, 1.36MB)
3 icons (each icon has pressed and not pressed: 2 states, using 1 png 400 * 400, 300KB each), i.e. 3 icon * 2 pic * 300KB = 1.8MB
some more textviews
When the app starts off and directly goes to this activity, everything is ok, the activity can be presented properly.
Yet somehow when the app has run for some other activities, and then goes to this activity through a dialog box, then most of the time errors will occur, as follows:
Out of memory on a 15728656-byte allocation.
Question:
I have researched for sometime and some say to bitmap.recycle(), yet how to implement? through the onCreate? or actually 400*400 is too big?
If I want to change the background of an activity upon users' choice, i.e. when he presses button A, the background changes to bgdA, presses button B will change background to bgdB... in that way how that can be achieved?
Many thanks!
Depending on where your asset is stored is the amount of memory it might take, since scaling factor is calculated between the difference of densities, this is a little gray area because I haven't found any official android documentation that backs this info up, however I've seen that error so many times and this is the way I handle it.
1.- If you don't have the asset in the proper drawable-(density), this will cause problems because depending on the devices you are actually supporting, you should put the asset in drawable-xxhdpi or drawable-xhdpi, you will notice how the memory will decrease considerably
2.- If you don't want to mess with densities because it's a generic image which don't have much details(like a simple background), then add the asset in the drawable-nodpi folder, it will prevent android from trying to scale the asset it self..
3.- As good practice, try to create the asset with the proper size for the proper densities, 400 x 400 seems like too much for an icon, this will also prevent you from OOM, not only in this activity, but for other activities that might also need to load a good amount of assets, giving scalability to your app..
Always take on count that leaving the "resize" of an Image to the OS might cause huge amounts of memory allocated because the OS will try to resize it based on the formula width * height * 4bytes, the 4 byes are for ARGB of each pixel, 1 byte per color or alpha, so if your image is for example 1090 * 1920, it could easily become internally 8.3MBs even tho the actual image size is only a few KBs, and if it tries to scale it, it might double it's size too.
Hope this Helps
Regards!
Make sure you have a copy of your image for every drawable folder in you res, for example if you runnig your app on the S4 phone and you don't have all the images in the drawable-xxhdpi folder you will run out of memory even with reasonably small images.
Also if you need to change background at run time use setBackgroundResource.
Hope it helps
This is the common problem in android here is the proper solution
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
In easy words you have to scale the image down according to your requirement
I have a background png in my Android application. I would like to support lots of displays, but I have this one obstacle - many displays have many resolutions and many ratios. I would like to make sure my background is displayed properly and make it more ellegant, than just creating 10+ cropped png files in Photoshop.
My idea would be - a fairly large picture imported in the project. The app would find out screen dimensions and simply say starting points(x,y) and ending points, that would "crop" the picture and display it without any deformations.
Is there a way of doing it?
I think bitmap.createBitmap() is the method your looking after. The method simply lets you cut out a defined portion of the bitmap.