Issue
Since starting android development I have have been using the following drawable folder structure...
drawable-mdpi drawable-hdpi drawable-xhdpi drawable-xxhdpi
now my problem is this, Im testing on 2 different devices
Lenovo Tab S8 - 1980*1200 - xxhdpi
Nexus 5 - 1080*1920 - xxhdpi
The lenovo tabs physical screen-size is about twice that of the Nexus, but they both pull their images from drawable-xxhdpi.
This means that if I initially build my app for the nexus, then when deployed on the Tab it will be surrounded by lots of blank unused space. But If I develop to fit nicely on the Tab it appears completely blown up on the Nexus.
I have read here
(http://www.techotopia.com/index.php/Handling_Different_Android_Devices_and_Displays)
to add a drawable folder with the name
drawable-sw200dp
drawable-sw600dp
drawable-sw800dp
to handle different screen sizes but this just crashes my app on the Nexus. Tab is fine.
Can anybody explain why this is and/or a workaround to handle different sizes within the xxhdpi category?
UPDATE:- XML layout that appears to be causing the 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 to Nexus with a 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>
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
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.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at 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 to allocate a 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>
Solution
@AndrewBramwell
Whats Your logcat throws
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 7607
http://developer.android.com/reference/java/lang/OutOfMemoryError.html
Too big for Android and it goes out of memory.So,best to resize
the images into smaller size.
And add this in your ImageView
android:adjustViewBounds="true"
Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.
Must be a boolean value, either "true" or "false".
You may set android:largeHeap="true"
in your manifest Application Tag .
Answered By - IntelliJ Amiya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.