How do I resolve the distortion that occurs when I switch from Portrait to Landscape?

Asked

Viewed 160 times

0

Normal view (Portrait)

For the display mode it looks normal, as you can see, now when I put it in Landscape mode...

I would like the background not to be distorted, as in the image above. For this I would like to list a way to display another image as background when the app was placed horizontally (Landscape) or so that the image I put did not distort, if there is any size that the android detects, at last...

NOTE - I HAVE CREATED AN IMAGE FOR HORIZONTAL MODE, ONLY I DO NOT KNOW IS THERE THE POSSIBILITY TO PUT IT TO BE DISPLAYED ONLY WHEN THE APP HAS LANDSCAPE MODE.

2 answers

1

Yes, it’s possible, using configuration qualifiers, which allow you to control how the system selects alternative features based on the screen features of the current device.

Configuration qualifiers are strings that are added to the names of the Android project’s resource directories.

In your case you should create a folder with the name res/drawable-land and place the image you want to use there when the device is in position Landscape. It must have the same name as used in mode Portrait.

  • Thanks in advance!!! I accessed the link you placed, I tried to create this folder, but nothing appeared.

  • It was because you did something wrong. See here how to create the folder.

  • The folder did not appear in Android Studio, but appeared when I went to see it in the explorer. Created it was indeed and added the second image. But it appeared in the drawable directory with "(land)" next to it.

  • See the reply which I indicated, there it is explained why you do not see the folder.

  • Very useful!!! I saw that it is always good to be alternating, depending on the need of the moment. VLW ^-^

0


There are two possible answers to your question. The first, and to which anyone would answer, is that the @Ramaral quoted.

In quotation to his comment, I will summarize it as a response. You will have to create two images, with the same name, but with appropriate resolutions to lang and port. To do this, set your /res should look like this:

Drawable-land  
      imagem.png   

Drawable-port
      imagem.png
  

There is a problem when performing such configuration: you would need to keep creating two images for each type of resolution, which is somewhat harmful.

The second answer is the simplest and most compact. You create only one image and use it at any resolution because the image is auto resizable.

The answer comes from a question I asked myself: When and why we should use SVG?

If we use SVG, create just one file and use it in different resolutions, without it losing quality. Follows the answer:

I learned how to vector "things" in Corel Draw, and this image business is not losing quality. (blabla)

From the Lollipop (API 21), Android included the class VectorDrawable, to define drawables based on vector graphics. The Android Studio 1.4 adds the Vector Asset Studio to make them easier to work with, including an SVG import feature and a new Gradle plugin that generates PNG versions of icons VectorDrawable at build time for API 20 and earlier versions. There are also third party tools to convert Svgs to VectorDrawables. Keep in mind that although the vector drawables can be set in XML, the file format is not SVG and not all SVG files can be converted successfully.

It is recommended to start a transition from PNG to SVG in the application?

According to the documentation, the use of vector characters instead of bitmaps reduces APK size because the same file can be resized to different screen densities without loss of image quality.

We have that each library added to a project brings many possibilities and features, but libraries usually contain a lot of code files and resources, among them, unnecessary resources depending on each type of situation. This creates a kind of residue: apps have a lot of things that are never really used. More than that, the size of the packages are growing at a fast pace. The point is, we should try to decrease as much as possible

inserir a descrição da imagem aqui

This image found on Wikipedia that better defines the Scalable Vector Graphics, illustrates the difference between bitmap and vector images. The bitmap image is composed of a fixed set of pixels, while the vector image is composed of a fixed set of shapes. In the image, the bitmap scale reveals the pixels when resizing the vector image preserves the shapes.

Read the documentation for more details.

  • Thanks for the answer. I’ll see what I’ll do based on what you said... [...] From Lollipop (API 21), Android included the Vectordrawable class, to define graphics-based drawables [...]" I’m making an app for Ice Cream Sandwich (4.0.3 API 15)I don’t think I can use that specifically.

  • That’s not necessary. You can use the Vectorasset normally. You will create a Vector from a . svg and will transform it into a file xml and use as image. It’s very simple.

  • Don’t forget that SVG support is limited, and its use is only appropriate for icons.

  • I already downloaded the Inkscape here. I will start the tests.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.