Use theme-defined settings OR from designer specification? - android

I have a design specification in PDF from my designer for all screens of my application. He made this specification according to Material Design Guidelines.
In this PDF all screen element sizes are specified. And I have all icon elements used in app in .png files. All of icons are exactly the same as in Material theme.
So the questions are: must I hardcode element sizes from specification or must I take them from correspinding sizes from theme? Must I put .png files from my designer to #drawable/ directory or must I use theme-defined icons?

Personally i save all my dimensions in a dimen.xml file and use them throughout my application. This allows for customization and if you ever want to adjust one margin, you can do it in one file and it will be set correctly in your entire application. It also gives you the ability to name your dimensions yourself, wich helps to make your code more readable. Here is a exampe of a dimen.xml file:
<resources>
<dimen name="action_button_min_width">56dip</dimen>
<dimen name="indeterminate_progress_size">32dp</dimen>
<dimen name="logoSize">#android:dimen/app_icon_size</dimen>
</resources>
EDIT: if you want to use a dimension given by android, but would prefer to give it another name, you can add it to your dimen.xml too, with another name. See the last dimen in the example.
If your designer has send you a document for you to follow, i'm sure he'd want some uniformity throughout the application. That's why google has released a big set of icons to choose from. This way, your app will have a consistent look & feel in all the windows from your app. Click here to check out the icon set.

Related

Should we use different dimen files for different screen sizes

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.

How to make UI in android for different devices

I'm fresher in Android & Coding. I have a task to design a popular game dots and boxes, for references https://en.wikipedia.org/wiki/Dots_and_Boxes . In this I have 7X7 cicles and used imageview to display all the stuff. My problem is how to design for multiple devices which looks as designed.
There is a great tool that lets you turn one image into multiple images for different screen densities: https://romannurik.github.io/AndroidAssetStudio/
There a few options there for generating the images, i use the Generic icons option since it allows an option for resizing the image.
if you use the generic option then:
Source: click image and upload the image (the circle for example).
Size and Padding: the defaults for size and padding are usually good enough.
Color: defaults to blue just move the seekbar to the far left in order to use the original color of the uploaded image.
Name and Download: at the bottom of the page you can rename the image see a preview and download as a zip.
Import: in the zipped file will be a res folder already structured properly by drawable densities and ready for you to just drag and drop into you /src/main folder.
P.S. Thank you to the person that made this tool your a genius and a life saver.
First of all use the unit dp for defining measurements. In addition to that, you have to define several values folders, where you define dimensions for scaling tablets or phones. E.g. define two values folders like:
values-large
values-xlarge
Now define a dimen.xml file inside this folders, where you can put your measurements in (unit dp) for the corresponding screensize. Define a measurement like this:
<dimen name="value1">17dp</dimen>
Then embedd this sizes in your layout xml, like:
android:layout_height="#dimen/value1"
Depending on the screensize, the system will load the correct measurements from this folders, e.g. if you have a screen size large only the defined values in folder values-large will be loaded. So instead of creating different layouts, define different measurements that can be loaded by the system automatically. For more information about this, also have a look at https://developer.android.com/distribute/essentials/quality/tablets.html

Do I need style file in each DPI folder?

If I have only one style file in values folder and it contains items refer to items from dimens file then I don't get right result. Only if I will have style file in each values folder (MDPI, HDPI, etc) I will get right result.
That is a bit strange because for drawable I could have files only in one folder and resources for different DPI in other folders and it works fine.
Could someone explain how Android search style items when I use references from dimens?
Here is a little example.
values/styles.xml
<resources>
<style name="message_item_topic">
<item name="android:textSize">#dimen/message_id_topic</item>
</style>
</resources>
values/dimens.xml
<resources>
<dimen name="message_id_topic">12sp</dimen>
</resources>
values-hdpi/dimens.xml
<resources>
<dimen name="message_id_topic">15sp</dimen>
</resources>
As per the Providing Alternate Resources guide:
Android supports several configuration qualifiers and you can add multiple qualifiers to one directory name, by separating each qualifier with a dash. Table 2 lists the valid configuration qualifiers, in order of precedence—if you use multiple qualifiers for a resource directory, you must add them to the directory name in the order they are listed in the table.
The rules for finding the best matching resource:
Eliminate resource files that contradict the device configuration. (Exception: DPI)
Pick the (next) highest-precedence qualifier in the list
Do any of the resource directories include this qualifier?
If No, return to step 2 and look at the next qualifier. (In the example, the answer is "no" until the language qualifier is reached.)
If Yes, continue to step 4.
Eliminate resource directories that do not include this qualifier
As per the flowchart:
Each resource is loaded according to these rules separately (i.e., a lookup for each dimen happens for each, independent of the other resources). Any display issues you are having are probably due to not knowing the difference between things that scale by DPI (dp and sp) and things that do not (px) - use dp and sp and you do not need to declare alternate resources (for anything but drawables) for different DPI devices.
If you were using px, cm, in, ... then a different dimens.xml in separate values-(l|m|h|xh|xxh)dpi would make sense.
Things are relative.
And there are too many devices around.
You'll never be sure your app will fit on EVERY existing device.
Some users will contact you and ask a fix for their device.
So, you'll read the specs, make an emulator, add the specific drawable/values and rerelease your app. Keep in mind that TABLETS will require special drawable/values folders.

In Android, what is the best way to define small tweaks to my style.xml or dimens.xml?

In Android, we can specify resources depending on the screen size by appending qualifiers to the folder names, such as "res/values-xlarge". I am working on a large enterprise application that has some fairly big styles.xml and dimens.xml files. Obviously, I do not want to duplicate the entire files for each screen size that needs some small tweaks.
What is the best way to specify tweaks to styles, dimens, and similar resources without duplicating the common parts?
Just specify the values you want to modify in the different folders, and leave the common ones on the lowest level. Styles will be a bit harder to do, but you can actually make a common style with all common values, then specify the differences in a different style that inherits from the first one.
For example, you can have a style A in res/values/ that has the common behaviour for all the different styles. However, in large screens (hdpi and xhdpi) you want to have a common behaviour you don't want in little screens: Just create a B style that inherits from A and has that behaviour in res/values, then specify the differences in res/values-xhdpi and res/values-hdpi.
If Android cannot find a value in R in a "proper" folder, it will search elsewhere until it finds said value.

Different dimension for different language

I'm working on a project, where in the textview the dimension of text is mentioned in a file main_dimens.xml in values-1024x768 folder. But i need a different text size for specific language(say pt).
<dimen name="main_digitalclock_size">18dp</dimen>
I need 12dp for pt language. So i tried to add the above line of code in strings.xml of values-pt folder, also created a folder values-pt-1024x768 and putted in it. But still size is 18dp only.
Are you sure you named your resource folders correctly? I looked up the rules that the Android OS uses when determining which resources to use here:
http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
It looks like the way to specify the usable screen size may be different from what you're using.

Categories

Resources