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>
You can create different layout for different orientation. In that way it is easy to maintain the UI part for any orientation.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.