I have a customized application , i install the app for select users . My application has separate drawable for each sizes (no problems with the drawables) , but my textViews and other content sizes does not change as per screen size . i have dimens values and i use only these 3 values across my 60 layouts, but Each time i install the app in client device, i change to values in dimens.xml according to the device inches and then build multiple apks for multiple screen size.
How do i solve this problem and make app fit all screen sizes ?
My dimens.xml
< // screen 6 inch <dimen name="radio_button_text_size" tools:ignore="MissingDefaultResource">13dp</dimen>
<dimen name="title_size" tools:ignore="MissingDefaultResource">13dp</dimen>
<dimen name="value_size" tools:ignore="MissingDefaultResource">15dp</dimen>
-->```
"'//screen 6+ inches
<dimen name="radio_button_text_size" tools:ignore="MissingDefaultResource">15dp</dimen>
<dimen name="title_size" tools:ignore="MissingDefaultResource">17dp</dimen>
<dimen name="value_size" tools:ignore="MissingDefaultResource">18dp</dimen>
"'
<!-- // screen 5inch
<dimen name="radio_button_text_size" tools:ignore="MissingDefaultResource">7dp</dimen>
<dimen name="title_size" tools:ignore="MissingDefaultResource">9dp</dimen>
<dimen name="value_size" tools:ignore="MissingDefaultResource">11dp</dimen>
-->
This happened to me as well a while back. I'm assuming you're using padding to position your views. Instead, you're gonna want to use a constraint layout and then use "horizontal bias" and "vertical bias" (the little scroll bars under the "Constraint Layout" section of the design view) to position your views. This will look the same on most screen sizes. Hope this helps!
Related
Currently, I'm developing Android app (phone only) and using only one size for different screen sizes, ie:
dimens.xml:
<dimen name="button_size">48dp</dimen>
<dimen name="text_size">16sp</dimen>
so in different screen sizes, we have only one size for components. And we go to this result: in small device, a textview can contain 10 chars but in larger device, a textview can contain 20 chars
And some developers use a gradle script to generate multiple dimens files in different folders based on the main dimens file like this:
values-sw320dp
dimens.xml:
<dimen name="button_size">48dp</dimen>
<dimen name="text_size">16sp</dimen>
values-sw480dp
dimens.xml:
<dimen name="button_size">52dp</dimen>
<dimen name="text_size">20sp</dimen>
...
so the system will use the dimens based on device size. And we go to this result: in small device and larger device, a textview can contain the same char, ie: 12 chars.
My question is: which one is better for UI, UX? (using Google Material Design)
You can use this library to support multiple screen dimen here
You can try this below, this will set automatically based on device.
?android:attr/textAppearanceMedium - For Medium font
?android:attr/textAppearanceSmall - For Small font
?android:attr/textAppearanceLarge - For Large font
Please check Material guidelines, To ensure usability for people with disabilities, give buttons a height of 36dp and give touchable targets a minimum height of 48dp.
Best practice is to use different dimens file for different devices. This will help you application view to be same across devices. If you keep same dimens for different devices then layout problem can also come. In some devices your layout will look perfectly fine but in another it will look very bad.
Android developer site also recommend to use different layout for supporting different devices.
I want to know if is there some web or something with examples of dimens.xml files to support multiple screen sizes?
Android runs on a variety of devices that offer different screen sizes and densities. For applications, the Android system provides a consistent development environment across devices and handles most of the work to adjust each application's user interface to the screen on which it is displayed. At the same time, the system provides APIs that allow you to control your application's UI for specific screen sizes and densities, in order to optimize your UI design for different screen configurations. For example, you might want a UI for tablets that's different from the UI for handsets.
Although the system performs scaling and resizing to make your application work on different screens, you should make the effort to optimize your application for different screen sizes and densities. In doing so, you maximize the user experience for all devices and your users believe that your application was actually designed for their devices—rather than simply stretched to fit the screen on their devices.
Follow This Link
Yes You can make folders of values for in which different dimens values are stored for multiple screen resolutions:
for example you can make folder in res named, values-720x1280, values-320x480, values-240x320 and put dimens.xml in each folder with different values in it...
you can define custom height with dimens(Suppose for 720X1280 device) like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="icon_width">55dip</dimen>
<dimen name="icon_height">55dip</dimen>
<dimen name="photo_width">170dip</dimen>
<dimen name="photo_height">155dip</dimen>
</resources>
and for values-320x480 dimens.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="icon_width">20dip</dimen>
<dimen name="icon_height">20dip</dimen>
<dimen name="photo_width">100dip</dimen>
<dimen name="photo_height">100dip</dimen>
</resources>
Then reference them in your other xml:
android:layout_height="#dimen/icon_height">
try it now and tell your experience
From HoneyComb, there is a new way to fix all of this. Your resources folder should now look like this:
I specify all font sizes in sp. The text looks good on several devices including Nexus 7, Galaxy S4 mini etc. However, on Galaxy S 3, the font is too large. Is this because the DPI of the S3 is so much more? If so, how do I adjust for this so that fonts display at relatively similar sizes?
DP/SP seems to be working properly. The larger font sizes I got was because of setting text sizes programmatically, using resource values which were already returned scaled - so essentially fonts were being double scaled. This could have been prevented by proper documentation by Android.
On my project i use different "dimens.xml" file for every type of density folder, for example:
values-mdpi
values-hdpi
values-xhdpi
dimens.xml has:
<!-- Text dimension for activity album preview -->
<dimen name="text_album_title">20sp</dimen>
<dimen name="text_album_author">18sp</dimen>
<dimen name="text_album_info">13sp</dimen>
<!-- Text dimension for row -->
<dimen name="text_track_title">16sp</dimen>
<dimen name="text_track_length">14sp</dimen>
And this is different for every file in folder. Is up to you to decide the size, you will see the difference between each dimension by using a layout with a TextView. Give it a try.
EDIT
I was totally wrong on this subject, thanks to Runloop and 323go.
I want to develop an app for smartphones and tablets. Now my problem is that my layout isn't scalled in the right dimensens. On a 10' tablet it looks like this:
But this here are screenshoots from a 7' tablet and from a smartphone:
I would like to set a min width and height for the ImageView and scale it up and down depending on the screen size so in each layout the ListView is visible. Which unit do I have to use for the ImageView width and height? I tried with dp, in and some more but that does not help...
Use
<ImageView
android:layout_width="#dimen/imageViewWidth"
android:layout_height="#dimen/imageVewHeight"
android:scaleType="fitXY"
/>
scaleType="fitXY" will scale your image and fit with ImageView width and height. This will solve your problem.
Edit
In your values directory, open strings.xml file, then add following lines
<dimen name="imageViewWidth">30dp</dimen>
<dimen name="imageViewHeight">30dp</dimen>
Now, open values-sw600dp directory (of not, create one) and open strings.xml file (if not, copy from other values directory).
<dimen name="imageViewWidth">100dp</dimen>
<dimen name="imageViewHeight">100dp</dimen>
Now, open values-sw720dp directory (of not, create one) and open strings.xml file (if not, copy from other values directory).
<dimen name="imageViewWidth">120dp</dimen>
<dimen name="imageViewHeight">120dp</dimen>
This will solve your problem of different sizes of ImageView for different layouts.
Still can't understand, read my answer at
Android Universal App Approach
Layouts on different models of mobiles
I need to be able to use relative sizes for paddings - to be bigger or smaller depending on the device's resolution and dpi.
For example, if my view is wide 100px, I'd like to have 10px padding left and 10px padding right.
But, if it runs on a higher density screen, and it is say 250px, I need the left and right padding to be both 25pixels each.
Hardcoding pixels or dp doesn't seem reasonable, also I prefer to avoid code-behind scaling logic if I can get away with it. I also prefer NOT to use any additional weighted empty views to gain the same effect. Not sure how I can simulate padding with it either way.
Is there a way to do this from the xml? Or do I have to scale them based on the device resolution/dpi from the code behind?
It's not really "relative sizes for paddings" but I think using an Android dimension value defined in XML will do what you want. It's hard to guess from your question as you want to avoid "hardcoding pixels" but also "do this from the xml" ;)
The link above gives this example;
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textview_height">25dp</dimen>
<dimen name="textview_width">150dp</dimen>
<dimen name="ball_radius">30dp</dimen>
<dimen name="font_size">16sp</dimen>
</resources>
Then;
<TextView
android:layout_height="#dimen/textview_height"
android:layout_width="#dimen/textview_width"
android:textSize="#dimen/font_size"/>
The Android SDK itself uses this approach;
In e.g. values/dimens.xml
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
values-sw600dp/dimens.xml
<resources>
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw600dp devices (e.g. 7" tablets) here.
-->
</resources>
You can target values-FOO at API levels, screen sizes, portrait vs landscape, combinations of the above "and more" when you are providing resources by using "Configuration qualifier names".