I wanted to update my searchBox width display upon device orientation
change.
I tried two options:
1. set res/layout-land/main.xml. I noticed that the layout is loaded
at the beginning of the application properly. However, if I change the
orientation while the application is still running, the layout is not
automatically updated to the correct form.
2. I use a single layout/main.xml, and set searchBox width inside
OrientationEventListener. I noticed that the width of the searchbox is
repainted correctly when I run the application for the first time on
the device (Nexus one), However after I exit the application and
launch the application again, the searchBox width will fail to update
width during orientation change. My debug shows that Edittext
setWidth() and invalidate() were called. The impact is that when the
application launched in horizontal position and switches to vertical,
the searchBox is NOT shortened as expected.
public void onCreate(Bundle savedInstanceState) {
...
OrientationEventListener mListener = new OrientationEventListener
(this,
SensorManager.SENSOR_DELAY_UI) {
public void onOrientationChanged (int orientation) {
Configuration cf = getResources().getConfiguration();
if (lastOrientation!=cf.orientation){
lastOrientation = cf.orientation;
searchBox.setWidth(getResources().getD
}
}
};
mListener.enable();
...
}
public void adjustOrientation(){
Configuration cf = getResources().getConfiguration();
float scale = getResources().getDisplayMetrics().density;
try {
int iconWidth = mSearchIcon.getWidth()>0?
mSearchIcon.getWidth():25;
int padding = (int)(30*scale);
mSearchBox.setWidth(getResources().getDisplayMetrics().widthPixels-
mAppTitle.getWidth()-iconWidth-padding);
mSearchBox.invalidate();
Log.d(LOG_TAG,"padding="+padding+" searchbox="+
(getResources().getDisplayMetrics().widthPixels-mAppTitle.getWidth()-
iconWidth-padding));
*/
mWebView.loadUrl("javascript:updateOrientation()");
} catch (Exception e) {
}
}
Can anyone advise what is the problem here. Is there any other way to
achieve this?
Thanks,
June Jorgensen
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en