1

I need to scale Relative Layout to size of device. Relative Layout have width = 2048 / height 6195.

Then in my activity I have width of device:

Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    Constants.sDeviceWidth= size.x;

Then I create Relative layout. And after it I scale my view. 1)Count scale:

 Float scale=(Constants.sDeviceWidth)/(float)newPage.getLayoutParams().width;

2) Set it:

 newPage.setScaleX(scale);
 newPage.setScaleY(scale);

3) Then I create parent view with red background for my relative layout:

       RelativeLayout baseLayout=new RelativeLayout(context);
       baseLayout.setLayoutParams(new RelativeLayout.LayoutParams((int) (pages.get(i).getLayoutParams().width * pages.get(i).getScaleX()), (int) (pages.get(i).getLayoutParams().height * pages.get(i).getScaleX())));
        baseLayout.addView(pages.get(i));
        baseLayout.setBackgroundColor(Color.RED);

where pages.get(i) is my child view which I scaled.

Then i found problem that for Nexus 7 all is ok but for Nexus 10 child view is to small. And I don`t know why. Nexus 10: 1

Nexus 7: 2

sofi37
  • 323
  • 1
  • 4
  • 15

1 Answers1

0

Am bit unclear in you question, do you want scale Relative Layout to size of device or screen ?

If its screen, its pretty simple if you set the width of the ViewGroup to match parent.

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"

What are your trying to achieve here ? If this is not what yo are trying to do. Please explain.

Prabhuraj
  • 928
  • 2
  • 8
  • 14