0

I have a layout with Viewgroup as parent containing a relativelayout with background image. I am adding controls dynamically to relativelayout and able to zoom and scroll it. When I change the orientation the background image shrink to fit landscape. I want to change the relativelayout controls in proportion to the background image. Iam a newbie to android so not clear where to start??

Layout

 <com.example.pdoc.zoomablepdf.ZoomableViewGroup
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:foregroundGravity="center"
 android:id="@+id/zoomLayout"
 xmlns:android="http://schemas.android.com/apk/res/android">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:background="@drawable/sample1pdf"
        android:id="@+id/RelLayout">            
    </RelativeLayout>
  </com.example.pdoc.zoomablepdf.ZoomableViewGroup>
dev_P
  • 73
  • 10

2 Answers2

0

You can create different layout for different orientation. In that way it is easy to maintain the UI part for any orientation.

Doctor Who
  • 747
  • 1
  • 5
  • 28
  • Actually I just want to proportionate the controls wrt background image, so I cant create a different layout for that... coz the background image also will change dynamically and controls are added dynamically – dev_P Sep 07 '16 at 10:12
0

I think you could use a onConfigurationChanged Listener. Something like this

    @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);

            // Checks the orientation of the screen
            if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {

                //Make your layout changes
            } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
                //other Changes (to default)
            }
        }

You can look here for more information: How to detect orientation

Community
  • 1
  • 1
Timo
  • 298
  • 1
  • 7
  • Actually I am using this event and identifying the orientation, my question is how to proportionate the controls added dynamically wrt background image..As the bg image height and width change according to orientation but the added controls are of earlier size.. I want them to proportionate that they look as part of the image only.. – dev_P Sep 08 '16 at 04:44