我正在关注
的教程当我尝试添加
时<!-- activity_main.xml in layout folder -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingTop="@dimen/activity_action_bar_overlay_margin">
<!-- dimens.xml in values folder -->
<dimen name="activity_action_bar_overlay_margin">?attr/actionBarSize</dimen>
然后我收到了以下错误:
01-25 23:10:33.132: E/AndroidRuntime(554): FATAL EXCEPTION: main
01-25 23:10:33.132: E/AndroidRuntime(554): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
01-25 23:10:33.132: E/AndroidRuntime(554): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.os.Handler.dispatchMessage(Handler.java:99)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.os.Looper.loop(Looper.java:137)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-25 23:10:33.132: E/AndroidRuntime(554): at java.lang.reflect.Method.invokeNative(Native Method)
01-25 23:10:33.132: E/AndroidRuntime(554): at java.lang.reflect.Method.invoke(Method.java:511)
01-25 23:10:33.132: E/AndroidRuntime(554): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-25 23:10:33.132: E/AndroidRuntime(554): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-25 23:10:33.132: E/AndroidRuntime(554): at dalvik.system.NativeStart.main(Native Method)
01-25 23:10:33.132: E/AndroidRuntime(554): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
01-25 23:10:33.132: E/AndroidRuntime(554): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
01-25 23:10:33.132: E/AndroidRuntime(554): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-25 23:10:33.132: E/AndroidRuntime(554): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.app.Activity.setContentView(Activity.java:1835)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:111)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
01-25 23:10:33.132: E/AndroidRuntime(554): at com.example.myfirstapp.MainActivity.onCreate(MainActivity.java:19)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.app.Activity.performCreate(Activity.java:4465)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
01-25 23:10:33.132: E/AndroidRuntime(554): ... 11 more
01-25 23:10:33.132: E/AndroidRuntime(554): Caused by: java.lang.reflect.InvocationTargetException
01-25 23:10:33.132: E/AndroidRuntime(554): at java.lang.reflect.Constructor.constructNative(Native Method)
01-25 23:10:33.132: E/AndroidRuntime(554): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
01-25 23:10:33.132: E/AndroidRuntime(554): ... 26 more
01-25 23:10:33.132: E/AndroidRuntime(554): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
01-25 23:10:33.132: E/AndroidRuntime(554): at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.view.View.<init>(View.java:2794)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.view.ViewGroup.<init>(ViewGroup.java:385)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.widget.LinearLayout.<init>(LinearLayout.java:174)
01-25 23:10:33.132: E/AndroidRuntime(554): at android.widget.LinearLayout.<init>(LinearLayout.java:170)
01-25 23:10:33.132: E/AndroidRuntime(554): ... 29 more
我想知道我是否必须使用RelativeLayout
才能使用?android:attr/actionBarSize
,效果实际上是什么样的?以及如何获得透明的操作栏?
欢呼声
答案 0 :(得分:9)
您的格式错误,应该是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingTop="?attr/actionBarSize">
您应该在dimens.xml
中定义尺寸,而不是在布局中。