Android Inflate View异常(Android Inflate View exception)

编程入门 行业动态 更新时间:2024-10-28 00:15:15
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.

更多推荐

本文发布于:2023-07-26 18:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1279569.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   Inflate   Android   exception   View

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!