Determining relative positions in a layout?

I need to implement a screen containing a list of blocks one below the other. Each block will contain elements of mutual overlapping (images, text), for which the relative position should be indicated relative to the upper left corner of the block.

I used to create a list of blocks ListView. For each block I tried to use a relative layout.This works fine when the phone is in landscape mode and the absolute position is indicated relative to the left edge of the phone. But when the phone is placed in portrait mode, the layout is distorted.

  • What layout can I use for this scenario?
  • Can I specify relative positions as a percentage of the screen width / height instead of pixels?
+3
source share
1 answer

You can use various layouts for portrait and landscape mode in the "layout-port" / "layout-land" folders, which will be automatically loaded when the screen orientation is changed. Check out Android docs or some books for a detailed explanation of how Android resolves the folder with the best matching resources.

Currently, the closest to the percentage width / height is LinearLayout.LayoutParams' layout_weight, which determines how much remaining space (from 0 to 1) should be occupied by this view / element.

+4
source

Source: https://habr.com/ru/post/1718911/


All Articles