-4

I am trying to setup a layout such that it has an image with regions. Those regions,can have either other ImageView or TextView. I am able to achieve this at a high level using FrameLayout and RelativeLayout. However, it does not scale properly on different devices.

As an example here is an image enter image description here

Yellow/Red Region - ImageView setup dynamically
Blue/Green Region - TextView

So On the Device, I want it to look like this:

enter image description here

And like this:

enter image description here

Note that Image scales correctly and so does child views in correct regions. Can someone please share some ideas on how this could be achieved?

Rishabh Srivastava
  • 3,683
  • 2
  • 30
  • 58
bond
  • 11,236
  • 7
  • 48
  • 62

4 Answers4

0

I was able to do this by writing a Custom View. I set the layout bonds based on the % offset. For example the image would start at 15% off top and 10% off left and width is 30% card size etc. I tested this with multiple devices and so far it is working as designed.

bond
  • 11,236
  • 7
  • 48
  • 62
  • The reason I accepted my own answer is because the solution to my problem can only be solved by Custom View as I described. Answers posted did not apply perhaps did not address the question I was asking. My question was about scaling the content maintaining the aspect ratio throughout the view and its children, the default way of padding with certain dp etc will not work because of different screen density. – bond Aug 13 '14 at 20:40
0

Have a look at Supporting Different Screen Sizes

Also have a look at Supporting Multiple Screens

This links has exactly what you are looking for. Follow the example and you will achieve the desired result.

These tutorials explains how to scale images based on the screen sizes and how to design your layout.

AnkitSomani
  • 1,152
  • 8
  • 9
-1

Extract from Google's dev site:-

  • Explicitly declare in the manifest which screen sizes your application supports
  • Provide different layouts for different screen sizes
  • Provide different bitmap drawables for different screen densities
Srikanth
  • 2,014
  • 19
  • 22
  • The question is asking how to configure a layout so I can fill in regions. Need to resolve this issue regardless of different bitmap drawables and layouts. – bond Jul 31 '14 at 02:38
-1

Use OnConfigurationChanged() to determine the orientation and changes the views according to your requirements

public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig)
{ 
if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){

    //Change the Layout width and height attributes according to your requirements
    Log.e("On Config Change","LANDSCAPE");
    }else{
    //Change the Layout width and height attributes according to your requirements
    Log.e("On Config Change","PORTRAIT");
    }

   base.OnConfigurationChanged(newConfig);

 }
Femil Shajin
  • 1,768
  • 6
  • 24
  • 38