我正在尝试设置自定义标题栏,它可以在应用启动时运行。我的自定义标题栏有一个按钮,单击该按钮会带您进入另一个活动。在活动完成后,它会跳回我的主要活动。然而,当它跳回来时,当我尝试设置自定义标题栏时,我在代码中得到一个错误为什么会发生这种情况。我查看了其他解决方案,但很多人都在谈论使用'BitmapFactory'来设置图像的大小,但如果是这样的话,为什么它会在启动时起作用?
这是我的代码
@Override
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
int [] progressVals = getPackets();
Log.i("DISPLAY ALL", "HERE 6");
displayList(progressVals, values);
Log.i("DISPLAY ALL", "HERE 7");
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
Log.i("DISPLAY ALL", "HERE 8");
menuHandler();
Log.i("DISPLAY ALL", "HERE 9");
pendingExerciseHandler();
Log.i("DISPLAY ALL", "HERE 10");
}
这是我的logcat
12-11 00:51:58.015: D/dalvikvm(307): GC_EXTERNAL_ALLOC freed 814 objects / 57696 bytes in 83ms
12-11 00:52:01.184: I/DISPLAY ALL(307): HERE 6
12-11 00:52:01.294: I/DISPLAY ALL(307): HERE 7
12-11 00:52:01.586: D/dalvikvm(307): GC_EXTERNAL_ALLOC freed 572 objects / 29720 bytes in 51ms
12-11 00:52:01.695: I/DISPLAY ALL(307): HERE 8
12-11 00:52:01.935: I/DISPLAY ALL(307): HERE 9
12-11 00:52:01.975: I/DISPLAY ALL(307): HERE 10
12-11 00:52:16.505: D/dalvikvm(307): GC_EXTERNAL_ALLOC freed 679 objects / 35472 bytes in 46ms
12-11 00:52:16.784: I/ADD PACKET(307): ON CREATE
12-11 00:52:18.705: W/KeyCharacterMap(307): No keyboard for id 0
12-11 00:52:18.705: W/KeyCharacterMap(307): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
12-11 00:52:21.645: I/ADD PACKET(307): DISPLAY LIST
12-11 00:52:21.875: D/dalvikvm(307): GC_EXTERNAL_ALLOC freed 4148 objects / 220688 bytes in 57ms
12-11 00:52:23.025: I/ADD PACKET(307): ITEM CLICKED
12-11 00:52:23.184: I/global(307): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
12-11 00:52:23.545: I/global(307): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
12-11 00:52:24.084: I/global(307): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
12-11 00:52:24.695: I/DISPLAY ALL(307): HERE 6
12-11 00:52:24.705: I/DISPLAY ALL(307): HERE 7
12-11 00:52:24.985: D/dalvikvm(307): GC_EXTERNAL_ALLOC freed 3708 objects / 1096704 bytes in 58ms
12-11 00:52:25.085: I/DISPLAY ALL(307): HERE 8
12-11 00:52:25.094: I/DISPLAY ALL(307): HERE 9
12-11 00:52:25.134: I/DISPLAY ALL(307): HERE 10
12-11 00:52:25.635: D/dalvikvm(307): GC_EXTERNAL_ALLOC freed 1675 objects / 94824 bytes in 54ms
12-11 00:52:26.525: D/dalvikvm(307): GC_EXTERNAL_ALLOC freed 217 objects / 10608 bytes in 47ms
12-11 00:52:29.035: I/global(307): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
12-11 00:52:32.545: I/RUN ALGO(307): Sports101
12-11 00:52:32.556: I/RUN ALGO(307): Sports101
12-11 00:52:32.556: I/RUN ALGO(307): Sports101
12-11 00:52:34.184: I/DISPLAY ALL(307): ON RESTART
12-11 00:52:34.417: I/DISPLAY ALL(307): HERE 6
12-11 00:52:34.435: I/DISPLAY ALL(307): HERE 7
12-11 00:52:34.644: E/dalvikvm-heap(307): 1584884-byte external allocation too large for this process.
12-11 00:52:34.644: E/GraphicsJNI(307): VM won't let us allocate 1584884 bytes
12-11 00:52:34.655: D/AndroidRuntime(307): Shutting down VM
12-11 00:52:34.655: W/dalvikvm(307): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-11 00:52:34.685: E/AndroidRuntime(307): FATAL EXCEPTION: main
12-11 00:52:34.685: E/AndroidRuntime(307): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dejalearn/com.dejalearn.base.DisplayAllActivity}: android.view.InflateException: Binary XML file line #27: Error inflating class <unknown>
12-11 00:52:34.685: E/AndroidRuntime(307): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.os.Looper.loop(Looper.java:123)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-11 00:52:34.685: E/AndroidRuntime(307): at java.lang.reflect.Method.invokeNative(Native Method)
12-11 00:52:34.685: E/AndroidRuntime(307): at java.lang.reflect.Method.invoke(Method.java:521)
12-11 00:52:34.685: E/AndroidRuntime(307): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-11 00:52:34.685: E/AndroidRuntime(307): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-11 00:52:34.685: E/AndroidRuntime(307): at dalvik.system.NativeStart.main(Native Method)
12-11 00:52:34.685: E/AndroidRuntime(307): Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class <unknown>
12-11 00:52:34.685: E/AndroidRuntime(307): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
12-11 00:52:34.685: E/AndroidRuntime(307): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-11 00:52:34.685: E/AndroidRuntime(307): at com.android.internal.policy.impl.PhoneWindow.onIntChanged(PhoneWindow.java:992)
12-11 00:52:34.685: E/AndroidRuntime(307): at com.android.internal.policy.impl.PhoneWindow.updateInt(PhoneWindow.java:2397)
12-11 00:52:34.685: E/AndroidRuntime(307): at com.android.internal.policy.impl.PhoneWindow.setFeatureInt(PhoneWindow.java:933)
12-11 00:52:34.685: E/AndroidRuntime(307): at com.dejalearn.base.DisplayAllActivity.onCreate(DisplayAllActivity.java:53)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-11 00:52:34.685: E/AndroidRuntime(307): ... 11 more
12-11 00:52:34.685: E/AndroidRuntime(307): Caused by: java.lang.reflect.InvocationTargetException
12-11 00:52:34.685: E/AndroidRuntime(307): at android.widget.ImageView.<init>(ImageView.java:108)
12-11 00:52:34.685: E/AndroidRuntime(307): at java.lang.reflect.Constructor.constructNative(Native Method)
12-11 00:52:34.685: E/AndroidRuntime(307): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
12-11 00:52:34.685: E/AndroidRuntime(307): ... 25 more
12-11 00:52:34.685: E/AndroidRuntime(307): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
12-11 00:52:34.685: E/AndroidRuntime(307): at android.graphics.Bitmap.nativeCreate(Native Method)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.content.res.Resources.loadDrawable(Resources.java:1709)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
12-11 00:52:34.685: E/AndroidRuntime(307): at android.widget.ImageView.<init>(ImageView.java:118)
12-11 00:52:34.685: E/AndroidRuntime(307): ... 29 more
12-11 00:57:34.749: I/Process(307): Sending signal. PID: 307 SIG: 9
12-11 04:52:37.645: D/dalvikvm(8984): GC_EXPLICIT freed 998 objects / 66296 bytes in 77ms
12-11 06:52:28.605: D/dalvikvm(8984): GC_EXPLICIT freed 269 objects / 12336 bytes in 95ms
这是我标题栏的xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:gravity= "center_vertical"
android:padding="5dp"
android:background="#01b8fa">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true">
<ImageButton
android:id="@+id/title_logo"
android:src="@drawable/edited_logo_2"
android:background="#00000000"
android:scaleType="fitXY"
android:layout_width="60dp"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/title_logo"
android:layout_marginLeft="-5dp"
android:layout_marginTop="-10dp">
<ImageView
android:id="@+id/notify"
android:background="#00000000"
android:src="@drawable/notify_bubble_blue"
android:scaleType="fitXY"
android:layout_width = "60dp"
android:layout_height="50dp"/>
<TextView
android:id="@+id/notify_number"
android:background="#00000000"
android:textSize="20sp"
android:textIsSelectable="false"
android:textColor="#FFFFFF"
android:paddingLeft="25dp"
android:paddingTop="10dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/title_name_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<TextView
android:id="@+id/title_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/app_name"
android:textColor="#ffffff"
android:textSize="38sp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/title_menu_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true">
<ImageButton
android:id="@+id/title_menu"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="20dp"
android:scaleType="fitXY"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="#00000000"
android:src="@drawable/menu_white" />
</RelativeLayout>
</RelativeLayout>
提前致谢