Localize resources, language, appearance and screen size
10 minute(s) read
Oct 03, 2021
In this case, you must consider all the conditions and standards of the countries so that you can design an application that is compatible with the standards and cultures of all countries. The only solution is to design the application in such a way that it changes the mode according to the place and place that is used and conforms to the conditions and standards there. In this tutorial, we will explain how to design an application and localize its resources.
Application Localization and String Resources
The application you are designing may be used in many countries in addition to your own country, in which case your languages may be different and the original language you may have considered for your application may be used in other countries. Do not use. For this reason, it is better to consider the language of other countries and present them in your application so that people from other countries can use it as well. Even in choosing colors and designs, you have to consider the culture of all countries to match their culture. In order to design an application whose resources and appearance are compatible with other countries and places, we must design it in such a way that according to the place where it is used, without changing the sources of the code, Adjust the appropriate settings for that location. In this way, it identifies the place where it is used and according to the desired place, loads and uses the appropriate resources and settings of that place.
For example, consider a program that is used in three different places, in which case the language used to display the texts is different.
The contents of the Main.axml file can be configured as follows:
<? xml version = "1.0" encoding = "utf-8"? >
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
android: orientation = "vertical"
android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
android: id = "@ + id / myButton"
android: layout_width = "fill_parent"
android: layout_height = "wrap content"
android: text = "@ string / hello"
Assets are a method that can be used to add different types of resources such as images, text, videos, music and XML. Assets added to your application are like files that exist inside your system and can be read using AssetManager.
In this part of the tutorial, we want to create an Assets text file and add it to our project, and then read it using AssetManager and display it in a TextView.
How to add an Assets to a project?
Assets are placed in a folder called Assets in the project. Create a text file inside this folder and select its name read_asset.txt. Then write a text inside the text file you created, such as: I am an asset. Visual Studio must set Build Action for this file to AndroidAsset, if set to BuildAction it ensures that the file is packaged in the APK at compile time.
How to read Assets in Xamarin?
Assets are read using AssetManager, Assets are read by AssetManager.
There is an example code below that opens Assets and reads its contents using AssetManager and displays it inside a TextView.
rotected override void OnCreate (Bundle bundle)
base. OnCreate (bundle);
// Create a new TextView and set it as our view
TextView tv = new TextView (this);
// Read the contents of our asset
AssetManager assets = this. Assets;
using (StreamReader sr = new StreamReader (assets. Open ("read_asset.txt")))
content = sr. ReadToEnd ();
// Set TextView.Text to our asset content
tv. Text = content;
Now it is time to run the program. Run the program by pressing Ctrl + f5.
Match the screen to any phone model
Android operating system or other operating systems are placed on different types of screens and are displayed to the user. In other words, operating systems that run on different types of smart devices and mobile phones may have different screen sizes. Phones are available in different sizes in the market and in order to be used by users, they need an operating system that launches user requests. But these phones can be designed and produced in different models and sizes; Therefore, the operating systems and applications designed for these phones must be able to adapt to any size of screen. In this part of the tutorial, we will teach you how to design an application that can be adapted and displayed with any size of phone screen.
Important terms to support different screen sizes:
- Screen Size:
This term is actually the amount of physical space that displays your applications on the phone . That is, the size it takes up to display applications to users.
- Screen Density:
This term is used to measure the number of pixels in a given section that determines screen density. The number of available pixels, which is the screen density, is measured in dpi per inch.
This term specifies the total number of pixels on the screen.
Density-independent pixel: This term is a virtual unit of measurement used to measure shells regardless of their density. This term is called dp for short. px = dp × dpi ÷ 160 This formula is used to convert dp to page pixels.
Orientation to specify how the program is displayed on the screen. The value of the orientation is automatically landscape, which indicates that the screen is wider. But when the screen is taller, not wider, the portrait value is used in the orientation. Of course, the orientation values can change during the time the user uses the phone and rotates it.
If we increase the screen resolution, but do not increase the screen density, we have actually increased the screen size. Otherwise, if we increase the screen resolution and density, the screen size will not change.
The relationship between screen pixel density and resolution and screen size is called screen complexity. To deal with this complexity of the screen and the relationship between them, the Android operating system Android framework uses dp or the same pixel without compression.
Definition of Screen Size
The screen size of each phone and hardware must be defined so that the application can place all its elements on the screen. In this case, the application must first specify the page size, and after detecting the screen size, it can place and display the elements on the screen based on it. It is important to recognize the screen size because if they are not detected, elements with inappropriate sizes may be placed too large or too small, in which case the proportion is not observed at all. Therefore, it is very important that the elements are placed according to the screen size, in which case the elements are displayed with full resolution and transparency. If there is no proportion between the size of the elements and the size of the screen, the elements are displayed in a blur. In Xamarin , you need to add an AndroidManifest.xml file to determine the screen size and the elements based on it.
The sizes of some physical devices and mobile phones with screen sizes are as follows:
Ordinary phone: 320dp:
An ordinary phone
A 5-inch tablet - tweener: 480dp:
Like Samsung Note
A 7-inch tablet - 600dp:
Like Barnes & Noble Nook
A 10-inch tablet - 720dp:
Like the Motorola Xoom
Android Asset Studio
Creating images with different densities can sometimes be very difficult or even impossible, which is why Google has developed an online tool that can eliminate the monotony and difficulty of creating bitmaps. This website and online tool Android Asset Studio can create a bitmaps and target the screen density in four modes.
Tips to consider for Multiple Screens
Android can be displayed on many devices with different screen sizes and densities, the following tips are about Multiple Screens, pay attention to them: Design and development for what you need: There are many devices on which applications can be displayed, but there are also some devices that have special factors and features. Screen Size and Density is a page provided by Google and can be used to specify breakdown, screen density and screen size.
Using DPs instead of Pixels:
If you use pixels to display and change screen density, they may cause problems and not work properly.
These have been removed in version and API level 3 (Android 1.5) and cause the use of fragile layouts. It is better to avoid these or use widgets that are a little more flexible such as LinearLayout, RelativeLayout and GridLayout.
Select an orientation by default:
Instead of providing alternative layout-port and layout-land resources, you can layout resources for the landscape in the layout.
Using LayoutParams for height and width:
When defining elements in an XML layout file, you can also specify its height and width. It is better to have a fit between the height and width and size of the screen so that the elements are displayed properly.
In this article, we learned how to design an application that meets all the standards of each country and place. We taught you how to design a program that can first receive and recognize the screen size and then determine and display the elements size based on the screen size. In this case, depending on the screen size of the hardware and physical device such as mobile and tablet, the size of the elements also changes. The size of the elements in the applications varies and depends on the size of the screen; Larger size elements will be displayed.About our Android and iOS app development services