1

In my application, a TextView is shown above an ImageView which contains a SVG image. Depending on the screen resolution, the ImageView, which is constrained (top and bottom e.g.) by another ImageView, is scaled: thus its SVG is also scaled by decreasing its height (and width, proportionnaly). Thus, the space between the TextView and the ImageView is technically the same than the one in Android Studio but is visually longer.

What I would want is: to keep the same space in Android Studio than on all screen resolutions, i.e.: 8dp.

Example:

In the Android Studio's visualizator, the space is 8dp:

enter image description here

In a Samsung Galaxy S7, I think the space is still 8dp but the SVG has been scaled: the space seems longer.

enter image description here

Proof that the SVG is scaled and that the ImageView is really at 8dp from the TextView:

enter image description here

Do you know how to keep the same space than in Android Studio, whatever the screen resolution?

Warning

I really want the SVG to be scaled (so I don't want, e.g. to set scale: fitXY or something like that). But I also want the space between the bottom of the TextView and the top of the scaled SVG be 8dp on all screen resolutions.

JarsOfJam-Scheduler
  • 2,809
  • 3
  • 31
  • 70

2 Answers2

0

This is a guess but I think that your image is causing the problem.

As you said - your space is the same 8dp all the time but because your image has a white background, when you use a bigger image the white background scales and it looks like the space between your text and image is larger.

You can use some view with non-white background and scale it for testing - I believe that you will see the same spacing regards the view size. If this will be the case maybe try to change your image.

Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
  • The image is a SVG with transparent background. Yes the `ImageView` is always 8dp, I'm sure since I just have set a background color to the `ImageView` and this background color is present just below the `TextView`. So the SVG is just scaled, and the top of the SVG is "far" below the top of its `ImageView`. – JarsOfJam-Scheduler Apr 07 '19 at 11:46
0

You can use LinearLayout layout with constraints to ensure a fixed proportion no matter what E.g

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:id="@+id/main_layout"
  android:orientation="horizontal"

>
    <ImageView
      android:id="@+id/img"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="40"
      />
    <TextView
      android:id="@+id/txt"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="60"

       />

 </LinearLayout>

So no matter what, in our example, the image will always be 40% of the horizontal space while the text will be 60%. I believe you can apply this idea to your situation

Tom
  • 41
  • 6
  • Even with a (vertical not horizontal) `LinearLayout` and the use of the weight concept, the SVG would be scaled no? Thus the problem won't be solved. – JarsOfJam-Scheduler Apr 07 '19 at 11:50