SimonVT / MessageBar提供layout_width属性

时间:2014-05-15 09:27:06

标签: android

我正在使用来自:Github

的SimonVT / MessageBar库

当我尝试在干净的项目中实现它时,我将收到以下错误:

05-15 11:19:27.430  26150-26150/be.appmax.messagebartestproject.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{be.appmax.messagebartestproject.app/be.appmax.messagebartestproject.app.MainActivity}: java.lang.RuntimeException: Binary XML file line #2: You must supply a layout_width attribute.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
            at android.app.ActivityThread.access$700(ActivityThread.java:159)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5419)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.RuntimeException: Binary XML file line #2: You must supply a layout_width attribute.
            at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:492)
            at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6056)
            at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6225)
            at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:610)
            at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:554)
            at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:56)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:486)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
            at net.simonvt.messagebar.MessageBar.<init>(MessageBar.java:53)
            at be.appmax.messagebartestproject.app.MainActivity.onCreate(MainActivity.java:21)
            at android.app.Activity.performCreate(Activity.java:5372)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
            at android.app.ActivityThread.access$700(ActivityThread.java:159)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5419)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
            at dalvik.system.NativeStart.main(Native Method)

我认为我正在以正确的方式使用它:)

MessageBar messageBar = new MessageBar(this);
messageBar.show("Test01");

有人知道如何使用图书馆吗?还是另一个做同样的图书馆?

这是库中出错的文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/mbContainer"
    style="?attr/messageBarContainerStyle">

    <TextView
        android:id="@id/mbMessage"
        style="?attr/messageBarTextStyle" />

    <TextView
        android:id="@id/mbButton"
        style="?attr/messageBarButtonStyle" />
</LinearLayout>

我的github测试项目是:My Test Project

2 个答案:

答案 0 :(得分:1)

检查thisthis

谷歌搜索此错误表明它是人为错误的9分(满分10分)。 尝试设置layout_widths,以便没有布局具有未定义的宽度。

尝试android:layout_width =&#34; fill_parent&#34;而不是match_parent,看看是否有任何改变

答案 1 :(得分:1)

我认为Google指南中记录的Snackbar是更好的解决方案)