我使用SimonVT/MessageBar庫來自:GithubSimonVT/MessageBar供應layout_width屬性
當我試圖實現在一個乾淨的項目,我會收到以下錯誤:
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
是啊,我用Google搜索的是:)但是,這是一個圖書館?我應該改變圖書館嗎?通常它應該只是工作:) – kevingoos
嘗試'android:layout_width =「fill_parent」'而不是match_parent,看看是否改變任何東西 – DerpyNerd
如果我改變庫中的佈局參數,那麼它是完全錯誤的:)它會顯示在右邊沒有佈局的上角落 – kevingoos