Android Question Catch Screen rotation and update widget

Discussion in 'Android Questions' started by ducphu, Feb 16, 2015.

  1. ducphu

    ducphu Active Member Licensed 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.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Your only other option is to create the xml layout yourself and create a layout that automatically adjusts based on the width and height.
     
  3. ducphu

    ducphu Active Member Licensed User

    So when the screen orientation is changed, the widget service is called from Service_Create or from Service_Start?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    No. Nothing is called.
     
  5. ducphu

    ducphu Active Member Licensed User

    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.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You cannot add an "if" statement to a XML layout file.
     
  7. ducphu

    ducphu Active Member Licensed User

    Hi, then how am I able to create a layout that automatically adjusts based on the width and height ? Can give me an example?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice