Android Inflate View异常(Android Inflate View exception)
我已经创建了一个应用程序,用于工作正常,直到我把它移动到gradle。
我有一个自定义Textview,我在XML中使用如下
<RelativeLayout android:id="@+id/text_message" style="@style/Container"> <co.customview.FontTextView android:id= "@+id/header_message" style= "@style/TextAppearance.SubTitle" android:layout_marginBottom="@dimen/gap_small" android:layout_width="wrap_content"/> </RelativeLayout>定义的样式如下
<style name="Container"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">wrap_content</item> </style> <style name="TextAppearance.SubTitle" > <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> </style>现在,对于每个自定义视图,我们开始低于错误
java.lang.RuntimeException: Unable to resume activity android.view.InflateException: Binary XML file line #57: Binary XML file line #57: You must supply a layout_height attribute. at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.view.InflateException: Binary XML file line #57: Binary XML file line #57: You must supply a layout_height attribute. at android.view.LayoutInflater.inflate(LayoutInflater.java:539) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at android.view.View.inflate(View.java:19784)I have created an app which use to work fine till I moved it to gradle.
I had a custom Textview and I used as below in XML
<RelativeLayout android:id="@+id/text_message" style="@style/Container"> <co.customview.FontTextView android:id= "@+id/header_message" style= "@style/TextAppearance.SubTitle" android:layout_marginBottom="@dimen/gap_small" android:layout_width="wrap_content"/> </RelativeLayout>Styles defined are as below
<style name="Container"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">wrap_content</item> </style> <style name="TextAppearance.SubTitle" > <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> </style>Now for each custom view we started getting below error
java.lang.RuntimeException: Unable to resume activity android.view.InflateException: Binary XML file line #57: Binary XML file line #57: You must supply a layout_height attribute. at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.view.InflateException: Binary XML file line #57: Binary XML file line #57: You must supply a layout_height attribute. at android.view.LayoutInflater.inflate(LayoutInflater.java:539) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at android.view.View.inflate(View.java:19784)最满意答案
更改
<co.customview.FontTextView android:id= "@+id/header_message" style= "@style/TextAppearance.SubTitle" android:layout_marginBottom="@dimen/gap_small" android:layout_width="wrap_content"/>至
<co.customview.FontTextView android:id= "@+id/header_message" style= "@style/TextAppearance.SubTitle" android:layout_marginBottom="@dimen/gap_small" android:layout_width="wrap_content" android:layout_height="wrap_content"/>你没有指定layout_height属性。
Change
<co.customview.FontTextView android:id= "@+id/header_message" style= "@style/TextAppearance.SubTitle" android:layout_marginBottom="@dimen/gap_small" android:layout_width="wrap_content"/>to
<co.customview.FontTextView android:id= "@+id/header_message" style= "@style/TextAppearance.SubTitle" android:layout_marginBottom="@dimen/gap_small" android:layout_width="wrap_content" android:layout_height="wrap_content"/>You have'nt specified layout_height attribute.
更多推荐
发布评论