0

First of all I'm quite new in layout development so sorry if this is a noob question. I'm trying to create an xml with a sort of an interactive background. So I put a background picture and added some ImageButtons with pictures like part of the background layout (to make them invisible).

Everything works as expected but the position of these ImageButtons change from the editor on the base of the device where the app is installed (or the AVD device too). I'm using a constraintlayout. At the moment, my ImageButtons xml is:

<ImageButton
    android:id="@+id/IB1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="83dp"
    android:layout_marginTop="14dp"
    android:layout_weight="1"
    android:background="@android:color/transparent"
    android:src="@drawable/IB1"
    android:scaleType="fitCenter"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

I understand that this happen because the background picture is resized on the base of the device screen where the app run (and this is in general correct because I want that the background cover all the layout space even if in portrait mode the picture is clearly very bad rendered; think to a tree, when you rotate the phone it is compressed on the vertical side and expanded on the horizontal side).

Exist a way to do what I want? Maybe with another type of layout or with some properties?

Thanks a lot for the help!

2
  • It sounds like the aspect ratio of your image is changing upon screen rotation. The full layout would be helpful, but look at ratio in ConstraintLayout if you want a consistent aspect ratio. If the image covers the entire screen, then you will need to do some cropping. Take a look at ImageView.ScaleType. Commented Nov 10, 2020 at 20:28
  • Thanks for the answer, by the way the main issue is the position of the buttons. They should remain overlap the background, even on different screens size (dpi). For example, if I put a button on the top left part of the screen; on the editor could be fine values like android:layout_marginStart="83dp" and android:layout_marginTop="14dp but on a different device (on AVD too), these values cannot be anymore correct because they make button in the same distance from top and right side but the background is not anymore there. I hope I have explained better Commented Nov 11, 2020 at 8:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.