gpt4 book ai didi

java - 为叠加操作栏指定布局上边距

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:15:11 25 4
gpt4 key购买 nike

我正在学习关于

的教程

Overlaying the Action Bar

当我尝试添加

<!-- 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,实际效果如何?以及如何获得透明的操作栏?

干杯

最佳答案

你的格式有误,应该是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingTop="?attr/actionBarSize">

您应该在 dimens.xml 中定义维度,而不是在布局中。

关于java - 为叠加操作栏指定布局上边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21357638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com