3

I have an application where I want to achieve a layout where the product image will be in the background and top of that to the right bottom, I want to place the price of the product and to the left bottom I want to place an add button.

Should I use frame layout or relative layout ???

AADProgramming
  • 6,077
  • 11
  • 38
  • 58
Narendra
  • 1,868
  • 6
  • 25
  • 39

3 Answers3

0

As a practical rule, I think it's up to you. I personally tend to use RelativeLayouts because they're more flexible, but you can achieve the same effect with either.

This SO post explains the performance differences between the two layouts in more detail: FrameLayout vs RelativeLayout for overlays

Community
  • 1
  • 1
VinceFior
  • 1,279
  • 13
  • 25
0

Relative layout: When you have relation between siblings or parent.

Frame layout: When siblings are placed independent of each other and are only dependent on parent.

Based on your situation, you can opt in of any of these.

Rahul
  • 4,699
  • 5
  • 26
  • 38
0

My advice, If you have specific size for your background for each device, then go for relative layout, and set the background to your image. Because when using background in RelativeLayout, It'll fit the size of the relative layout itself, whether the image suits the size of the RelativeLayout or not. (Can be stretched/pixelated/Not properly added)

If you're not sure about specific size, you should use FrameLayout, with ImageView, that handles the ScaleType, which can be centerCrop, and it'll fit the layout in good shape. And for the TextView, use layout_gravity, which will handle the position based on the parent layout.

devMohaned
  • 135
  • 6