Android Question Catch Screen rotation and update widget

ducphu

Active Member
Licensed User
Longtime User
Hi all,

I have a homescreen widget, when the screen orientation is changed, I want to load a corresponding layout, e.g portrait_layout, landscape_layout. Also, when the screen orientation is changed, my widget data is lost, e.g my textbox all blank. I read Peter Simpson solution by using a timer to catch the rotation. Is there other solution for this, because I dont want to run the widget so frequent as it may drain much battery.
 
So when the screen orientation is changed, the widget service is called from Service_Create or from Service_Start?
 
Upvote 0
Hi all,

I'm not good at xml. Can anyone show me an example how to modify a xml layout file, using "if" statement. For example, if screen orientation is portrait then the code is
Code:
<ImageView android:scaleType="fitXY" android:id="@+id/widget2x2s_imageview1" android:layout_width="20dp" android:layout_height="20dp" android:layout_x="3dp" android:layout_y="40dp" android:visibility="visible" />

If screen orientation is landscape, I want to layout_width to 15dp, layout_height to 15dp, layout_y to 30dp.
Thanks in advance.
 
Upvote 0
Hi, then how am I able to create a layout that automatically adjusts based on the width and height ? Can give me an example?
 
Upvote 0
Back
Top