Handling different screen sizes (Android) -


since starting android development have have been using following drawable folder structure...

drawable-mdpi drawable-hdpi drawable-xhdpi drawable-xxhdpi

now problem this, im testing on 2 different devices

lenovo tab s8 - 1980*1200 - xxhdpi
nexus 5 - 1080*1920 - xxhdpi

the lenovo tabs physical screen-size twice of nexus, both pull images drawable-xxhdpi.

this means if build app nexus, when deployed on tab surrounded lots of blank unused space. if develop fit nicely on tab appears blown on nexus.

enter image description here enter image description here

i have read here

(http://www.techotopia.com/index.php/handling_different_android_devices_and_displays)

to add drawable folder name

drawable-sw200dp
drawable-sw600dp
drawable-sw800dp

to handle different screen sizes crashes app on nexus. tab fine.

can explain why and/or workaround handle different sizes within xxhdpi category?

update:- xml layout appears causing proble (fragment_tutorial2.xml)...

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"                 android:paddingtop="20dip">     <textview         android:id="@+id/hint"         style="@style/tutorialtitle1"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:text="@string/tut_text2" />      <textview         android:id="@+id/hint2"         style="@style/tutorialtitle2"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_below="@id/hint"         android:text="@string/tut_text3"/>      <imageview         android:id="@+id/documentlist"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centervertical="true"         android:layout_centerhorizontal="true"         android:src="@drawable/documentlist" />  </relativelayout> 

styles....

<style name="tutorialtitle1" parent="appbasetheme">         <item name="android:textstyle">bold</item>         <item name="android:gravity">center</item>         <item name="android:textsize">50sp</item>         <item name="android:textcolor">@color/white</item>         <item name="android:paddingtop">5dp</item>     </style>      <style name="tutorialtitle2" parent="appbasetheme">         <item name="android:textstyle">bold</item>         <item name="android:gravity">center</item>         <item name="android:textsize">20sp</item>         <item name="android:textcolor">@color/white</item>         <item name="android:paddingbottom">25dp</item>     </style> 

logcat when publishing nexus folder called drawable-sw200dp ...

2243-2243/uk.co.danbd.heswresources e/androidruntime﹕ fatal exception: main     process: uk.co.danbd.heswresources, pid: 2243     android.view.inflateexception: binary xml file line #21: error inflating class <unknown>             @ android.view.layoutinflater.createview(layoutinflater.java:633)             @ com.android.internal.policy.impl.phonelayoutinflater.oncreateview(phonelayoutinflater.java:55)             @ android.view.layoutinflater.oncreateview(layoutinflater.java:682)             @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:741)             @ android.view.layoutinflater.rinflate(layoutinflater.java:806)             @ android.view.layoutinflater.inflate(layoutinflater.java:504)             @ android.view.layoutinflater.inflate(layoutinflater.java:414)             @ uk.co.danbd.heswresources.tutorialfragment.oncreateview(tutorialfragment.java:105)             @ android.support.v4.app.fragment.performcreateview(fragment.java:1789)             @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:955)             @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1138)             @ android.support.v4.app.backstackrecord.run(backstackrecord.java:740)             @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1501)             @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:490)             @ android.support.v4.app.fragmentpageradapter.finishupdate(fragmentpageradapter.java:141)             @ android.support.v4.view.viewpager.populate(viewpager.java:1105)             @ android.support.v4.view.viewpager.populate(viewpager.java:951)             @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1473)             @ android.view.view.measure(view.java:17547)             @ android.widget.relativelayout.measurechildhorizontal(relativelayout.java:727)             @ android.widget.relativelayout.onmeasure(relativelayout.java:463)             @ android.view.view.measure(view.java:17547)             @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5535)             @ android.widget.framelayout.onmeasure(framelayout.java:436)             @ android.view.view.measure(view.java:17547)             @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5535)             @ android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1436)             @ android.widget.linearlayout.measurevertical(linearlayout.java:722)             @ android.widget.linearlayout.onmeasure(linearlayout.java:613)             @ android.view.view.measure(view.java:17547)             @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5535)             @ android.widget.framelayout.onmeasure(framelayout.java:436)             @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2615)             @ android.view.view.measure(view.java:17547)             @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:2015)             @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1173)             @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1379)             @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1061)             @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5885)             @ android.view.choreographer$callbackrecord.run(choreographer.java:767)             @ android.view.choreographer.docallbacks(choreographer.java:580)             @ android.view.choreographer.doframe(choreographer.java:550)             @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:753)             @ android.os.handler.handlecallback(handler.java:739)             @ android.os.handler.dispatchmessage(handler.java:95)             @ android.os.looper.loop(looper.java:135)             @ android.app.activitythread.main(activitythread.java:5257)             @ java.lang.reflect.method.invoke(native method)             @ java.lang.reflect.method.invoke(method.java:372)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698)      caused by: java.lang.reflect.invocationtargetexception             @ java.lang.reflect.constructor.newinstance(native method)             @ java.lang.reflect.constructor.newinstance(constructor.java:288)             @ android.view.layoutinflater.createview(layoutinflater.java:607)             at com.android.internal.policy.impl.phonelayoutinflater.oncreateview(phonelayoutinflater.java:55)             at android.view.layoutinflater.oncreateview(layoutinflater.java:682)             at android.view.layoutinflater.createviewfromtag(layoutinflater.java:741)             at android.view.layoutinflater.rinflate(layoutinflater.java:806)             at android.view.layoutinflater.inflate(layoutinflater.java:504)             at android.view.layoutinflater.inflate(layoutinflater.java:414)             at uk.co.danbd.heswresources.tutorialfragment.oncreateview(tutorialfragment.java:105)             at android.support.v4.app.fragment.performcreateview(fragment.java:1789)             at android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:955)             at android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1138)             at android.support.v4.app.backstackrecord.run(backstackrecord.java:740)             at android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1501)             at android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:490)             at android.support.v4.app.fragmentpageradapter.finishupdate(fragmentpageradapter.java:141)             at android.support.v4.view.viewpager.populate(viewpager.java:1105)             at android.support.v4.view.viewpager.populate(viewpager.java:951)             at android.support.v4.view.viewpager.onmeasure(viewpager.java:1473)             at android.view.view.measure(view.java:17547)             at android.widget.relativelayout.measurechildhorizontal(relativelayout.java:727)             at android.widget.relativelayout.onmeasure(relativelayout.java:463)             at android.view.view.measure(view.java:17547)             at android.view.viewgroup.measurechildwithmargins(viewgroup.java:5535)             at android.widget.framelayout.onmeasure(framelayout.java:436)             at android.view.view.measure(view.java:17547)             at android.view.viewgroup.measurechildwithmargins(viewgroup.java:5535)             at android.widget.linearlayout.measurechildbeforelayout(linearlayout.java:1436)             at android.widget.linearlayout.measurevertical(linearlayout.java:722)             at android.widget.linearlayout.onmeasure(linearlayout.java:613)             at android.view.view.measure(view.java:17547)             at android.view.viewgroup.measurechildwithmargins(viewgroup.java:5535)             at android.widget.framelayout.onmeasure(framelayout.java:436)             at com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2615)             at android.view.view.measure(view.java:17547)             at android.view.viewrootimpl.performmeasure(viewrootimpl.java:2015)             at android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1173)             at android.view.viewrootimpl.performtraversals(viewrootimpl.java:1379)             at android.view.viewrootimpl.dotraversal(viewrootimpl.java:1061)             at android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5885)             at android.view.choreographer$callbackrecord.run(choreographer.java:767)             at android.view.choreographer.docallbacks(choreographer.java:580)             at android.view.choreographer.doframe(choreographer.java:550)             at android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:753)             at android.os.handler.handlecallback(handler.java:739)             at android.os.handler.dispatchmessage(handler.java:95)             at android.os.looper.loop(looper.java:135)             at android.app.activitythread.main(activitythread.java:5257)             at java.lang.reflect.method.invoke(native method)             at java.lang.reflect.method.invoke(method.java:372)             at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903)             at com.android.internal.os.zygoteinit.main(zygoteinit.java:698)      caused by: java.lang.outofmemoryerror: failed allocate 7607 

tutorialframent.java (within oncreateview() ) ....

switch (page) {             case 0 :                 rootview = (viewgroup) inflater.inflate(r.layout.fragment_tutorial1, container, false);                 animateimageview((imageview) rootview.findviewbyid(r.id.imageview1),r.anim.fadescalein,1000);                 animateimageview((imageview) rootview.findviewbyid(r.id.imageview2),r.anim.fadescalein,2000);                 animateimageview((imageview) rootview.findviewbyid(r.id.imageview3), r.anim.fadescalein, 2100);                 animateimageview((imageview) rootview.findviewbyid(r.id.imageview4), r.anim.fadescalein, 2200);                 animateimageview((imageview) rootview.findviewbyid(r.id.imageview5), r.anim.fadescalein, 2300);                 animateimageview((imageview) rootview.findviewbyid(r.id.imageview6), r.anim.fadescalein, 2400);                 animateimageview((imageview) rootview.findviewbyid(r.id.imageview7), r.anim.fadescalein, 2500);                 animateimageview((imageview) rootview.findviewbyid(r.id.imageview8), r.anim.fadescalein, 2600);                 animateimageview((imageview) rootview.findviewbyid(r.id.imageview9), r.anim.fadescalein, 2700);                 break;             case 1 :                 rootview = (viewgroup) inflater.inflate(r.layout.fragment_tutorial2, container, false); // line 105                 break;             case 2 :                 rootview = (viewgroup) inflater.inflate(r.layout.fragment_tutorial3, container, false);                 break;             case 3 :                 rootview = (viewgroup) inflater.inflate(r.layout.fragment_tutorial4, container, false);                 break;             case 4 :                 rootview = (viewgroup) inflater.inflate(r.layout.fragment_tutorial5, container, false);                 break;             case 5 :                 rootview = (viewgroup) inflater.inflate(r.layout.fragment_tutorial6, container, false);                 listview = (listview) rootview.findviewbyid(r.id.list);                 if (prefs.getstring("type", "acute") == "acute") {                     arrayadapter<string> adapter = new arrayadapter<string>(getactivity(), r.layout.tutorial_layout_row, valuesacute);                     listview.setadapter(adapter);                 } else {                     arrayadapter<string> adapter = new arrayadapter<string>(getactivity(), r.layout.tutorial_layout_row, valuesmentalhealth);                     listview.setadapter(adapter);                 }                 listview.setonitemclicklistener(listpairedclickitem);                 break;         }         return rootview; 

fragment_tutorial1.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"                 android:paddingtop="20dip" >      <imageview         android:id="@+id/imageview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparenttop="true"         android:layout_centerhorizontal="true"         android:layout_margintop="@dimen/logo_margin_top"         android:src="@drawable/doctorslogo" />      <imageview         android:id="@+id/imageview2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centervertical="true"         android:layout_centerhorizontal="true"         android:src="@drawable/ecg" />      <imageview         android:id="@+id/imageview3"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_torightof="@id/imageview2"         android:layout_aligntop="@id/imageview2"         android:src="@drawable/handwash" />      <imageview         android:id="@+id/imageview4"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_above="@id/imageview2"         android:layout_alignright="@id/imageview2"         android:src="@drawable/chart" />      <imageview         android:id="@+id/imageview5"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_toleftof="@id/imageview2"         android:layout_aligntop="@id/imageview2"         android:layout_margintop="-40dp"         android:src="@drawable/cross" />      <imageview         android:id="@+id/imageview6"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@id/imageview5"         android:layout_toleftof="@id/imageview2"         android:src="@drawable/steph" />          <imageview         android:id="@+id/imageview7"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_toleftof="@id/imageview2"         android:layout_alignbottom="@id/imageview2"         android:layout_marginbottom="-49dp"         android:src="@drawable/hygieia" />      <imageview         android:id="@+id/imageview8"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@id/imageview2"         android:layout_alignleft="@id/imageview2"         android:src="@drawable/hospital" />      <imageview         android:id="@+id/imageview9"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_torightof="@id/imageview2"         android:layout_below="@id/imageview2"         android:src="@drawable/droplet" />  </relativelayout> 

@andrewbramwell

whats logcat throws

caused by: java.lang.outofmemoryerror: failed allocate 7607

http://developer.android.com/reference/java/lang/outofmemoryerror.html

too big android , goes out of memory.so,best resize images smaller size.

and add in imageview

android:adjustviewbounds="true" 

set true if want imageview adjust bounds preserve aspect ratio of drawable.

must boolean value, either "true" or "false".

you may set android:largeheap="true" in manifest application tag .


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -