0
我有背景的圖像集,但充氣佈局時,我得到錯誤:錯誤:InflatingException - 內存不足
04-01 10:01:29.591: E/AndroidRuntime(12502): FATAL EXCEPTION: main
04-01 10:01:29.591: E/AndroidRuntime(12502): android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.LayoutInflater.createView(LayoutInflater.java:626)
04-01 10:01:29.591: E/AndroidRuntime(12502): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
04-01 10:01:29.591: E/AndroidRuntime(12502): at com.mobilion.fragment.ScreenFragment.onCreateView(ScreenFragment.java:144)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.View.measure(View.java:16831)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:651)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.View.measure(View.java:16831)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.View.measure(View.java:16831)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245)
04-01 10:01:29.591: E/AndroidRuntime(12502): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:302)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.View.measure(View.java:16831)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-01 10:01:29.591: E/AndroidRuntime(12502): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2586)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.View.measure(View.java:16831)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2189)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1352)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1535)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.Choreographer.doCallbacks(Choreographer.java:591)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.Choreographer.doFrame(Choreographer.java:561)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.os.Handler.handleCallback(Handler.java:730)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.os.Handler.dispatchMessage(Handler.java:92)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.os.Looper.loop(Looper.java:176)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.app.ActivityThread.main(ActivityThread.java:5419)
04-01 10:01:29.591: E/AndroidRuntime(12502): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 10:01:29.591: E/AndroidRuntime(12502): at java.lang.reflect.Method.invoke(Method.java:525)
04-01 10:01:29.591: E/AndroidRuntime(12502): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
04-01 10:01:29.591: E/AndroidRuntime(12502): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
04-01 10:01:29.591: E/AndroidRuntime(12502): at dalvik.system.NativeStart.main(Native Method)
04-01 10:01:29.591: E/AndroidRuntime(12502): Caused by: java.lang.reflect.InvocationTargetException
04-01 10:01:29.591: E/AndroidRuntime(12502): at java.lang.reflect.Constructor.constructNative(Native Method)
04-01 10:01:29.591: E/AndroidRuntime(12502): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.view.LayoutInflater.createView(LayoutInflater.java:600)
04-01 10:01:29.591: E/AndroidRuntime(12502): ... 48 more
04-01 10:01:29.591: E/AndroidRuntime(12502): Caused by: java.lang.OutOfMemoryError
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
04-01 10:01:29.591: E/AndroidRuntime(12502): at android.gr
代碼
@SuppressWarnings("deprecation")
private void setTargetBackground(int target,int[] phone,int[] tablet) {
tableRowDayOne.getChildAt(1).setBackgroundDrawable(null);
tableRowDayOne.getChildAt(2).setBackgroundDrawable(null);
tableRowDayOne.getChildAt(3).setBackgroundDrawable(null);
tableRowDayOne.getChildAt(4).setBackgroundDrawable(null);
tableRowDayOne.getChildAt(5).setBackgroundDrawable(null);
tableRowDayOne.getChildAt(6).setBackgroundDrawable(null);
tableRowDayTwo.getChildAt(1).setBackgroundDrawable(null);
switch (target) {
case Navigation.TARGET_FASTING:
tableRowDayOne.getChildAt(1).setBackgroundResource(R.drawable.shape_datetarget);
if (DeviceUtil.isTablet(getActivity().getApplicationContext())) {
imageViewBackground.setImageResource(tablet[bgPosition]);
}else{
imageViewBackground.setImageResource(phone[bgPosition]);
}
return;
case Navigation.TARGET_SUN:
tableRowDayOne.getChildAt(2).setBackgroundResource(R.drawable.shape_datetarget);
if (DeviceUtil.isTablet(getActivity().getApplicationContext())) {
imageViewBackground.setImageResource(tablet[bgPosition]);
}else{
imageViewBackground.setImageResource(phone[bgPosition]);
}
return;
case Navigation.TARGET_MIDDAY:
tableRowDayOne.getChildAt(3).setBackgroundResource(R.drawable.shape_datetarget);
if (DeviceUtil.isTablet(getActivity().getApplicationContext())) {
imageViewBackground.setImageResource(tablet[bgPosition]);
}else{
imageViewBackground.setImageResource(phone[bgPosition]);
}
return;
case Navigation.TARGET_MIDAFTERNOON:
tableRowDayOne.getChildAt(4).setBackgroundResource(R.drawable.shape_datetarget);
if (DeviceUtil.isTablet(getActivity().getApplicationContext())) {
imageViewBackground.setImageResource(tablet[bgPosition]);
}else{
imageViewBackground.setImageResource(phone[bgPosition]);
}
return;
case Navigation.TARGET_NIGHT:
tableRowDayOne.getChildAt(5).setBackgroundResource(R.drawable.shape_datetarget);
if (DeviceUtil.isTablet(getActivity().getApplicationContext())) {
imageViewBackground.setImageResource(tablet[bgPosition]);
}else{
imageViewBackground.setImageResource(phone[bgPosition]);
}
return;
case Navigation.TARGET_ISHA:
tableRowDayOne.getChildAt(6).setBackgroundResource(R.drawable.shape_datetarget);
if (DeviceUtil.isTablet(getActivity().getApplicationContext())) {
imageViewBackground.setImageResource(tablet[bgPosition]);
}else{
imageViewBackground.setImageResource(phone[bgPosition]);
}
return;
case Navigation.TARGET_NEXT_FASTING:
tableRowDayTwo.getChildAt(1).setBackgroundResource(R.drawable.shape_datetarget);
if (DeviceUtil.isTablet(getActivity().getApplicationContext())) {
imageViewBackground.setImageResource(tablet[bgPosition]);
}else{
imageViewBackground.setImageResource(phone[bgPosition]);
}
return;
}
//imageViewBackground.setScaleType(ScaleType.CENTER);
}