我创建了一个应用程序,用于正常工作,直到我将其移动到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)
答案 0 :(得分:0)
更改
<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 属性。