安卓有个我很讨厌的V7包,该包找不到源码,找不到jar文件。今天,使用PopuMenu时,写了如下代码:
//public boolean onCreateOptionsMenu(Menu menu) {
// getMenuInflater().inflate(R.menu.core_more_popmenu, menu);
// return true;
//}
private void showPopwinMenu(View v) {
PopupMenu popupMenu = new PopupMenu(CoreFactoryActivity.this, v);
getMenuInflater().inflate(R.menu.core_more_popmenu, popupMenu.getMenu());
popupMenu.show();
}
但是,一直崩溃。各种错误找不到。经过怀疑阶段:代码错误——Activity不支持错误,仔细阅读了一堆红色的。发现,V7包出现了,起初,我只以为是安卓系统运行时自己调用的。。。后来一想,不对啊。我根本没有使用V7包的哪个特性。于是,仔细对照了错误代码,发现坑爹的事实:
V7包居然也有PopMenu类,而且使用该类,在FragmentActivity,Activity下都会崩溃行。看来这坑货没有什么用
崩溃代码:
09-11 23:11:03.567: E/AndroidRuntime(25133): FATAL EXCEPTION: main
09-11 23:11:03.567: E/AndroidRuntime(25133): Process: com.yue.madou, PID: 25133
09-11 23:11:03.567: E/AndroidRuntime(25133): java.lang.RuntimeException: Binary XML file line #17: You must supply a layout_height attribute.
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:528)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6215)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6383)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:677)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:621)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:60)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.view.LayoutInflater.inflate(LayoutInflater.java:480)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.support.v7.view.menu.MenuPopupHelper$MenuAdapter.getView(MenuPopupHelper.java:374)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.support.v7.view.menu.MenuPopupHelper.measureContentWidth(MenuPopupHelper.java:223)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:157)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.support.v7.view.menu.MenuPopupHelper.show(MenuPopupHelper.java:129)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.support.v7.widget.PopupMenu.show(PopupMenu.java:216)
09-11 23:11:03.567: E/AndroidRuntime(25133): at com.yue.madou.activity.CoreFactoryActivity.showPopwinMenu(CoreFactoryActivity.java:122)
09-11 23:11:03.567: E/AndroidRuntime(25133): at com.yue.madou.activity.CoreFactoryActivity.access$2(CoreFactoryActivity.java:119)
09-11 23:11:03.567: E/AndroidRuntime(25133): at com.yue.madou.activity.CoreFactoryActivity$2.onClick(CoreFactoryActivity.java:65)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.view.View.performClick(View.java:4489)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.view.View$PerformClick.run(View.java:18962)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.os.Handler.handleCallback(Handler.java:808)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.os.Handler.dispatchMessage(Handler.java:103)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.os.Looper.loop(Looper.java:193)
09-11 23:11:03.567: E/AndroidRuntime(25133): at android.app.ActivityThread.main(ActivityThread.java:5542)
09-11 23:11:03.567: E/AndroidRuntime(25133): at java.lang.reflect.Method.invokeNative(Native Method)
09-11 23:11:03.567: E/AndroidRuntime(25133): at java.lang.reflect.Method.invoke(Method.java:515)
09-11 23:11:03.567: E/AndroidRuntime(25133): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
09-11 23:11:03.567: E/AndroidRuntime(25133): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:657)
09-11 23:11:03.567: E/AndroidRuntime(25133): at dalvik.system.NativeStart.main(Native Method)
09-11 23:11:06.195: E/(25661): appName=com.yue.madou, acAppName=/system/bin/surfaceflinger
09-11 23:11:06.195: E/(25661): 0