S
The theme "supply multiple screens/screens", although not complex, contains many aspects so it becomes difficult to approach it completely in the stackoverflow response format.I will address only the aspects that I think are the most relevant to your understanding. Features of the screen.Screen size(Screen size) - It is measured from the diagonal of the screen, expressed in inches(swelling). Android sets four groups for screen size:small(small)normal(normal)great(large) extra large(xlarge). Screen resolution(Screen Resolution) - Number of pixels the screen contains.Screen density(Screen density) - Calculated depending on the above, it is the reason between a certain number of pixels and the size occupied by them on the screen, is expressed in dpi(dots per inch).Android sets 6 groups for screen density: low(I'm sorry.)average(mdpi)high♪)extra-alta(xhdpi)extra-extra-alta(xxhdpi)extra-extra-extra-alta(xxxhdpi). Concepts.Screen orientation(Screen Orientation) - The screen orientation towards the user: vertical/ portrait(bytraint)horinzontal/paisage(landscape). Independent pixel of density(Density-independent pixel) - Expressed in dp, it is a "virtual" unit that allows the values of dimensions to be interpreted in order to occupy the same physical space, whatever the density of the screen.1dp is equivalent to a physical pixel on a 160 dpi screen, which is the density of an average density screen(mdpi).By expressing the dimensions in dp the system will draw the views in order to have the same physical dimension, regardless of screen density. If the dimension is expressed in pixeis(px) the actual size of the views will decrease with increased density. Scalable pixels(scalable pixels) - Expressed in sp, is the equivalent of dp for the dimension of texts. Configuration Qualifiers - A qualifier is a string used in the name of the resource folders, in the Android project, to specify the configuration for which the features should be used.The system will choose, among the available features, the most suitable for the device screen characteristics. Support multiple screens.Responsive layouts (adaptable).In the vast majority of situations, multiple screen support is achieved automatically by the system if, when drawing the layout, choose the attributes and dimensions carefully. Dimensions - Use preferably "wrap_content" and/or "match_parent".Mainly "match_parent", which allows the views to adjust their size to the available space. In a LinearLayout, use android:layout_weight to proportionally distribute the existing space that each view must occupy. If you have to use a fixed value, always use the dp or sp drive.Positioning - In order for the positioning of the views to be adjusted to the available dimensions should position them one in relation to the other, using type attributes android:layout_alignParentLeft and android:layout_below, in the case of RealtiveLayout, or android:layout_gravity and android:layout_weight in a LinearLayout. Do not use margins to position views. Margins should only be used to create an engaging space. For large and complex layouts consider using the new https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html . In it the positioning is defined with relationships between views. It is more flexible than RelativeLayout and easier to use with Android Studio Layout Editor.Alternative layoutsDue to the wide variety of dimensions of existing screens and the orientation in which it is being used, the desired results are not always obtained only with the adaptability of the layout.In the case of small screens, because there is not enough space. On very large screens, for poor use of existing space.In such cases they must be made available layouts alternatives.Alternative layouts should be placed in folders using, in their name, the https://developer.android.com/guide/practices/screens_support.html#qualifiers for which they are intended. To qualify a configuration you can use more than one qualifier.For example, one layout to be used on an ldpi screen in horizontal orientation/reading should be placed in the folder with the name res/layout-land-ldpi. To avoid repeating code, place the common parts of layout in separate files and use <include layout=""/> No layout final. Alternative BitmapsBy adapting the dimensions of ImageView depending on screen density, the system needs to resize the images in order to be rendered to the proper physical size. This resizing may cause loss of image quality.To ensure to maintain quality, alternative versions must be made available for each screen density. The bitmaps Alternatives should be placed in folders using, in their name, the density qualifier for which they are intended. You should create in the folder \res new drawable folders, one for each density, in the form drawable-xxx, where xxxx is: I'm sorry.mdpi♪xhdpixxhdpiThe size of the images, to include in each of them, is calculated by multiplying the image dimensions in the folder res/drawable-mdpi the value resulting from the formula factor = dpi/160. The factors to be applied to common densities are: == sync, corrected by elderman ==mdpi => 1hdpi = 1.5xhdpi => 2xxhdpi => 3In the case of icons, to use in the various parts of the user interface, and to maintain consistency between applications, see https://developer.android.com/guide/practices/ui_guidelines/icon_design.html in addition to other aspects to be taken into account, know what dimensions to use.Android Studio provides https://developer.android.com/studio/write/image-asset-studio.html?utm_source=android-studio#about that, starting from an initial image, automatically generates the others for each of the habitually used resolutions.Final notes.When creating/manipulating java layouts please note that most (I would say all but not sure) methods use dimensions expressed in pixels. Before using them converts the dp values to pixeis.To make this conversion you can use the following method:public static int convertDpToPixels(float dp, Activity context){
DisplayMetrics metrics = new DisplayMetrics();
context.getWindowManager().getDefaultDisplay().getMetrics(metrics);
float density = metrics.density;
return (int) Math.ceil(dp * density);
}
https://developer.android.com/studio/run/managing-avds.html for the most common types of screens and test yours layouts. Although they are not 100% reliable, they can detect most of the problems. Keep them layouts simple. Not only are they easier to manage how they provide a better user experience.Read the documentation of the various types of ViewGroup available to get to know the attributes available for positioning views.References. https://developer.android.com/guide/practices/screens_support.html . https://developer.android.com/guide/topics/resources/providing-resources.html . https://material.io/guidelines/layout/units-measurements.html# . https://developer.android.com/studio/run/managing-avds.html . https://developer.android.com/training/constraint-layout/index.html . https://developer.android.com/guide/practices/ui_guidelines/icon_design.html .