android - "values-w320dp-land" folder doesn't apply on screen landscape rotation -


i have following 2 values folders under project resources :

  1. this dimens.xml portrait display of 320dp width screen :

enter image description here

  1. this dimens.xml landscape display of 320dp width screen :

enter image description here

what i'm getting correct display @ application start (for landscape display portrait display) :

  • application starts in portrait mode correctly :

enter image description here

  • application starts in landscape mode correctly :

enter image description here

now problem when rotate screen during application runtime (say application first started in portrait mode), application doesn't seem retrieve values correct values folders supposed "values-w320dp-land" :

enter image description here

and vice-versa, if rotate screen after started application in ladscape mode, application doesn't seem retrieve values correct values folders supposed "values-w320dp-port", , :

enter image description here

update 1

this activity declaration in androidmanifest.xml :

    <application         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme"         android:name=".utils.json.volleyapplication" >          <activity             android:name="com.test.momo.categoriesactivity"             android:label="@string/app_name"             android:configchanges="orientation|screensize" >             <intent-filter>                 <action android:name="android.intent.action.main" />                 <!--monitor changes in connectivity-->                 <!--<action android:name="android.net.conn.connectivity_change"/>-->                 <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>  </application> 

and gridview declaration in activity layout :

<gridview xmlns:android="http://schemas.android.com/apk/res/android"             android:id="@+id/gridview_categories"             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:columnwidth="@dimen/gridview_row_item_size"             android:numcolumns="@integer/num_columns"             android:verticalspacing="@dimen/gridview_row_item_spacing"             android:horizontalspacing="@dimen/gridview_row_item_spacing"             android:stretchmode="none"             android:layout_marginleft="@dimen/gridview_row_item_spacing"             android:layout_marginright="@dimen/gridview_row_item_spacing"             android:scrollbars="none"/> 

update 2

so got close solution. when rotate screen @ runtime, gridview adjusts portrait ot landscape mode correctly after did changes on code of activity here :

@override public void onresume() {     super.onresume();      gridview.setnumcolumns(getresources().getinteger(r.integer.num_columns));     gridview.setcolumnwidth(getresources().getdimensionpixelsize(r.dimen.gridview_row_item_size)); }  @override public void onconfigurationchanged(configuration newconfig) {     super.onconfigurationchanged(newconfig);      gridview.setnumcolumns(getresources().getinteger(r.integer.num_columns));     gridview.setcolumnwidth(getresources().getdimensionpixelsize(r.dimen.gridview_row_item_size)); } 

except that, when (and when) rotate screen portrait landscape @ runtime :

enter image description here

as can see, first element of gridview seems preserve height , width values of portrait mode. while rest of gridview elements display correctly.

what missing here?

when specify android:configchanges in manifest, activity receive onconfigurationchanged callback. implementation follows:

@override public void onconfigurationchanged(configuration newconfig) {     // absolutely detach adapters lists.     // recyclerview adapters have caches need cleared.     // can reuse adapter not widgets.     mlist.setadapter(null);      // inflate new view hierarchy.     setcontentview(r.layout.the_same_layout_as_in_on_create);      // update variables point newly inflated widgets     butterknife.bind(this); // update variables point       // reattach adapters     mlist.setadapter(madapter);      // here follows else touches widgets in oncreate... } 

please note if changed language on phone activity still full restart since it's not in android:configchanges.

also note when using approach activity not follow lifecycle onpause-onstop-ondestroy-oncreate-onstart-onresume.

my advice learn how save state , fragments , recreate whole activity. expensive operation inflating layout , have anyway.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -