Consider what I need on the example of this cat:

cat original

Suppose, in my application, this cat is a background attribute in the root layout in the main_activity.xml file.

First, if the device screen is smaller than a cat, then the cat should be compressed, but not cut off. And so that there is no empty space left on the screen . I.e:

cat does not want to be without a head

That's the way it happens by default, but there’s one more thing second: all the view-elements on the screen should also be compressed and remain on that part of the cat where they were originally, that is:

view-elements should not run away from the cat

In general, this is all that I need, but it should be on every device , taking into account the tablets.

I read a lot on the Internet about all these screen cases, but there is no complete picture. And I need a complete sequence of actions :

  • what kind of layout you need to create?
  • What are the drawable subfolders for drawable ?
  • what permission do seals do?
  • write something in AndroidManifest ?
  • and something else that I don't know ..?
  • one
    imkho, your incorrect is actually correct. You are in the browser, for example, where the thread is seen, so that when you resize the window, everything is compressed, including fonts? If you need distortions, I am afraid you will have to draw all this into a bitmap and display it as a distorted picture, well, that is, write your own engine ... The layout should be adaptive. - Yura Ivanov
  • @YuraIvanov, but there are several density types of screens (mdpi, hdpi, xhpdi, xxhdpi), and on the off site android there is a whole article about density independence, where the screenshot shows just the result that I need. I just don’t understand how they achieved this. And every normal android application looks the same on all devices. How do professionals solve this problem? - i am so lame
  • You are confusing density and size. It shows that on phones with different densities, pictures will be displayed equally if the corresponding daddies are decomposed with the corresponding image sizes. It has nothing to do with distortion, and especially with other views. - Yura Ivanov
  • @YuraIvanov, yes, density, by and large I meant it! After all, there are only two main types of aspect ratio, and if you create an xml file with a bitmap from a cat, you will have to sacrifice the entire edge of the ear. Please write the answer about supporting all the densities of the screen, including the tablet! - i am so lame
  • one
    It is unlikely that I will succeed, and moreover briefly, than on the corresponding sites. There is a startandroid.ru for example, read there. In addition, the question does not correspond to what you are asking to tell ... - Yura Ivanov

1 answer 1

The behavior you require can basically be achieved using the following markup:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:background="@drawable/kotic" > <View android:layout_height="0dp" android:layout_width="match_parent" android:layout_weight="6"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/white" style="@android:style/TextAppearance.Medium" android:text="This is TextView"/> <View android:layout_height="0dp" android:layout_width="match_parent" android:layout_weight="3"/></LinearLayout> 

Kitty fills the entire place - both in landscape and portrait orientations. Checked on the phone and tablet. The inscription is located on the same spot of the cat.

If you look for inconsistency, then this is not an entirely proportional change in the size of the text (especially noticeable in width). Here, of course, you could also tinker and recalculate the font size, based on the number of pixels of the screen. And assign this font size programmatically. But it seems to me that you should not strain so much, since the result is quite bearable. If you climb into such a jungle, then you will encounter problems like: what if the text does not fit on one line? etc.

About different densities. The picture safely stretched to the screen size on both the phone and the tablet. Both devices with normal density. For high density it would be nice to provide a bigger picture. For low density, it is smaller so that it takes up less space and there were no image artifacts when processing an image that is too detailed for a screen with few pixels, although this may be superfluous.