I am developing an application that will run on two devices, a J2 smartphone with a 5-inch display (960x540) and a 7-inch tablet (800x1280). I'm having trouble making screens responsive to both screens. I created dimens.xmls files with different dimensions for the respective screens, as shown below.
I created two dimension files.
where in the large-hdpi are the font sizes, icons, margins and paddings for the tablet's 7 inch screen.
and in this dimension, they are the sizes referring to the 5 inch screen.
Although I made the two dimension files, for each screen with different sizes, when running the application run on both devices, only the configuration contained in large-hdpi that works on both screens. If I change a font size in large-hdpi, in the preview of android studio, it already shows me the change in the 5 inch screen, and it was to change only in the 7 inch screen. So, I would like to know how I can have different sizes for these two screens.
According to the official Android documentation, these two resolutions belong to the "large" qualifier/group. This is the reason that both receive the same dimen values.
https://developer.android.com/training/multiscreen/screensizes#TaskUseSizeQuali
Although, this type of qualifiers should only be used with earlier versions of Android (versions 3.1 and earlier), which most probably you won't be supporting in your project.
Instead, you should use the smallest width qualifiers which are density-independent and you can define the exact density-independent pixels on your values files. You can read more here:
https://developer.android.com/training/multiscreen/screensizes#TaskUseSWQuali
Related
I just tried out the JavaFX Hello World Example on a 4k screen on Arch Linux, but unfortunately the GUI does not scale.
The documentation says
Hi-DPI support. JavaFX 8 now supports Hi-DPI displays.
So how can I make my application dpi aware?
Hi-DPI support on various devices
For OS X Macs with retina display it should "just work" - JavaFX is aware of Hi-DPI Macs and will scale the UI appropriately. If you set the spacing in a VBox to 8, then that is a device independent unit; on a non-retina display mac it will take up 8 pixels, on a retina display which has double the resolution, the spacing will take up 16 pixels. Because the retina display also has twice the DPI as well as twice the resolution of the non-retina display, the physical screen measurement of the space will be the same regardless of device.
For Windows and Linux devices, your results may be less satisfactory as JavaFX 8u20 does not currently by default work out arbitrary DPI resolutions on such devices and scale to them appropriately. What you could do is perform most of your measurements in css as em units (which are based on the point size of the scene's root's default font) and similarly for fxml, and then set the point size of the scene root's default font appropriately depending on what you determine from querying the screen's DPI resolution. See the discussion in this answer for further information and sample code: javafx automatic resizing and button padding.
Specific to Gnome
Gnome 3 has a setting for the scaling factor which can be controlled by this command:
gsettings set org.gnome.desktop.interface scaling-factor 2
You can query this scaling factor by reading the user's gnome profile settings and use this in conjunction with querying the screen DPI to work out how an appropriate scaling factor then apply the scaling using the techniques described above.
Just a personal anecdote - when I tried using Gnome 3 scaling (CentOS 7 and also a recent Fedora release) on a Hi-DPI display a couple of days back, I found the overall support for Hi-DPI across applications running under Linux to be pretty spotty. Certainly, the support was much improved from CentOS 6 when I attempted that, but there was still quite a way to go to achieve quality Hi-DPI support across windowing toolkit, standard apps and third party apps. For this reason, I believe that running HiDPI Gnome desktops is still quite a bleeding edge thing which is definitely not for everyone - I am sure that this situation will change over time.
Bitmapped Images
From a JavaFX team lead blog entry on Hi-DPI:
In Apple’s applications (starting with the iPhone and iPad with their retina displays), the solution to the problem is for the application developer to supply two images instead of one for each image asset. For example, the splash screen will be supplied with two images, one at normal resolution and one at 2x the resolution. The files are named the same but the 2x one is named according to some convention, such that at runtime the platform will lookup the 2x version on retina behind the scenes. In such a way, your application says “fooImage.png” but “fooImage#2x.png” is looked up instead when on a machine with a retina display.
I do not know whether this bitmapped image choosing functionality for Hi-DPI displays is currently in Java 8u20 or not - you might have to implement it yourself by querying the screen with screen.getDpi(), then loading the appropriate bitmap.
4K Devices
4K is a lot of pixels to push. JavaFX will by default use hardware a accelerated graphics pipeline when such a graphics pipeline is available. Some graphics hardware may not be fully optimized for 4K display (e.g. not enough video ram), which might lead to an application which either does not work or performs poorly. I also don't believe that currently a lot of effort has gone into investigating JavaFX performance on various 4K devices - it might "just work", but it might not either. You will need to test your application on the target hardware to determine the current capabilities of JavaFX applications when running on that hardware. You might also need to tweak the application according to some of the suggestions above.
A user has reported an issue with JavaFX 8u20 when attempting to display a 4K video using JavaFX:
JavaFX Ultra HD (4K) video
Background
Supporting Hi-DPI under OS X was (likely) simpler than Windows/Linux devices as the target devices are either retina or non-retina display with one being an exact 2x scale of the other and direct support from the OS X system can be leveraged to help achieve the retina scaling. With Windows/Linux, probably what is required is an ability to scale at factors other than just 2x, and that is covered by the (currently outstanding and scheduled) feature request RT-32521 Support global coordinate scaling with DPI-based default. Scaling by an integral amount usually gives the best visible results.
Additional Resources
Kynosarges discussion of JavaFX DPI Scaling.
The JavaFX team load wrote a blog on JavaFX on retina Macs (this is a little dated now, as JavaFX now supports retina Macs).
Randahl's perspective on JavaFX: Designing for Multiple Resolutions.
Apple have some nice advice on optimizing applications for high resolution devices, it's not JavaFX specific and some of the advice does not apply to JavaFX, but there are still some useful general principals and techniques there.
A complete guide to coding for Hi-DPI devices is outside the scope of this particular answer - you can google various web resources to get more information.
If you have further questions on Hi-DPI support for JavaFX, I suggest you ask them on the openjfx-dev JavaFX developer mailing list.
Wiki Answer
This answer may have some possible inconsistencies or errors and may date over time. I have made the answer community wiki. If you are aware of specific corrections, device and OS limitations or support model support for Hi-DPI on JavaFX, please feel free to edit this answer or move it to the OpenJFX wiki (where it probably belongs anyway).
I faced the same problem. I built javaFX application in my surface pro 3, which did not scale but the fxml apps did. then I installed jre8u221 withiout replacing the updated version it suggested. It fixed the problem
I have installed robowm and created the sample app given on the offical website.
It works perfectly on emulator with screen size of 3.5 inch, but black bars occur on top and bottom of screen when I test it with 4 inch emulator or iPhone 5.
Seems like robovm is not supporting 4 inch screen size.
Does anyone know how to solve this problem?
RoboVM definitely supports the 4 inch screen. You just have to tell iOS that your app supports the larger screen. The way to do this is to provide a launch screen with the right name and dimensions. Put an image named Default-568h#2x.png with dimensions 640x1136 pixels in your resources/ folder in your RoboVM project and iOS will let your app use the full screen.
I am developing android applications from last four months, but still i am not able to design UI which will support for maximum screens. What should be my ideal layout and drawable structure and what is the good way should i follow to achieve it. Please help me.
Thanks in advance.
Well the best way to do that will be:
the same icon with different sizes and put them in order in the(these are order from smaller sizes to bigger sizes):
mdpi
ldpi
hdpi
xhdpi
Th OS will automatically get you the best icon to fit the screen.
Obviously if you want to run your apps in tablets as well it will be extremely hard to achieve a layout that can be compatible with thousands of devices available on the market.
For that you can create different layout folders and create several of them for different screen sizes.
For more info you should definitely see this dev page:
http://developer.android.com/guide/practices/screens_support.html
Hope this helps
Use RelativeLayout or LinearLayout with weights. So that you get same view on most on screens. You can use one copy of images with good resolution in drawable folder that can adjust on most screens or different sizes images in different drawable folders but its increase your app size. But its always good practise to create layout depend on different sizes and some layouts based on height and width.
I'll quote the top answer of this thread which is pretty much equal to your question.
That may not be possible. However you can look at these links and
learn how to provide different images(pixels and density), layouts and
further on. It may not be possible to make a userinterface on a low
level density screen the same way as a high density screen and then
you can target different layouts to different phones e.g.
Providing Resources
Application Resources
You should also have a look at this: Best practice supporting multiple screens.
Although it is possible you should focus on a few main densities/screen sizes which you will support. Test these and make sure they work as you want them to do. It will be very much work to support all varieties and may not pay off because only few phones use specific sizes.
Best way to implement Fragment
And also use import any icon with the following steps
Right click on Project
select ->new -> other..
Then choose Android Icon Set
Launcher Icons, Icon Name
so on...
You can follow this tutorial http://www.vogella.com/tutorials/AndroidFragments/article.html
I've got Android application running in landscape mode on 10" tablet with 1280x800 px resolution. App contains web view including picture with 1280x720 px size, so it's kind of full screen web view.
If I run the very same application on HTC One X smartphone, which is 4.7", 720 x 1280 px, also in landscape mode, web view seems to display only part of the picture, much less as I would expect. It even looks like physical 1/4 of the original, top left quarter.
Does anybody have any experience of running same app on similar or even different resolutions with completely different physical screen sizes?
Any recommendations?
For instance, I would like to run this app also on 7" tablets, where the resolution is only 1024x600 px. Can I still do that without need of changing picture size?
That is just the behavior of a web view/web page in general. Unless you tell it to with JavaScript or css, it wont care how big your screen is and will display all the content at the exact pixel size specified. You can more than likely dynamically re-size the image with JavaScript or css.
This may be what you are looking for: How can I resize an image dynamically with CSS as the browser width/height changes?
According to this thread:
Android Webview initial zoom out
This is the right answer:
webview.getSettings().setLoadWithOverviewMode(true);
This will cause the webview to be zoomed out initially.
webview.getSettings().setUseWideViewPort(true);
The Webview will have a normal viewport (like desktop browser),
You can create separate stylesheets for each density.
http://developer.android.com/guide/webapps/targeting.html#DensityCSS
just to conclude this, all changes had to be done on portal side in html, js and css in order to display it correctly on various tablets.
Playing with settings of WebView element didn't help in this case.
I have optimized my app for just about all Android phones. The way my app is set up, I have a 16dp padding on the left and right side of it and a 65dp padding on top and bottom (see screenshot below). On a phone it looks beautiful.
But on a tablet, it looks terrible. 65dp on a phone is a whole lot different that 65dp on a tablet. On a tablet, the black border around the question runs off the side of the scroll background and stuff is on the roll at the top and bottom of the scroll background.
What are my options to fix this? Is there a percentage/weight option for padding? I think that would solve it completely but there is nothing like that that I know of.
You can create multiple resource files tailored for different display sizes. Android will automatically choose the correct resource file for you. Using this technique, you can specify padding values for any screen size, or even completely unique layouts, to be automatically selected for you by Android.
Please refer to Designing for Multiple Screens.
Using multiple dimension resource files would make the task of changing the padding based on screen size very simple. See More Resource Types.