致命异常:主java.lang.RuntimeException:二进制XML flie line#21:您必须提供layout_height属性

时间:2016-03-14 03:34:29

标签: java android xml android-layout android-linearlayout

我已经提供了layout_value但仍然收到此错误:

03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime: Process: pupccb.solutionsresource.com, PID: 15246
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime: java.lang.RuntimeException: Binary XML file line #21: You must supply a layout_height attribute.
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:492)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5949)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6117)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1831)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1743)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:58)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:757)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at com.orhanobut.dialogplus.Utils.getView(Utils.java:49)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at com.orhanobut.dialogplus.DialogPlusBuilder.getFooterView(DialogPlusBuilder.java:276)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at com.orhanobut.dialogplus.DialogPlus.<init>(DialogPlus.java:111)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at com.orhanobut.dialogplus.DialogPlusBuilder.create(DialogPlusBuilder.java:265)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at pupccb.solutionsresource.com.util.CreateMaterialDialog.<init>(CreateMaterialDialog.java:50)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at pupccb.solutionsresource.com.activity.TicketDetails.newCommentDialog(TicketDetails.java:248)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at pupccb.solutionsresource.com.activity.TicketDetails.onClick(TicketDetails.java:146)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.view.View.performClick(View.java:4455)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:18448)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:733)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:149)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5064)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
03-14 10:47:37.988 15246-15246/pupccb.solutionsresource.com E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
03-14 10:47:39.388 15246-15246/pupccb.solutionsresource.com I/Process: Sending signal. PID: 15246 SIG: 9

这是XML布局:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="fill_parent">

    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        card_view:cardElevation="0dp">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="@dimen/pad_50dp"
            android:gravity="center_horizontal"
            android:orientation="vertical"
            android:padding="@dimen/pad_5dp">

            <EditText
                android:id="@+id/editTextComment"
                style="@style/editext_graybg"
                android:layout_width="fill_parent"
                android:layout_height="@dimen/pad_50dp"
                android:ems="10"
                android:gravity="left|top"
                android:hint="@string/comment_details"
                android:inputType="textMultiLine"
                android:maxLength="255"
                android:padding="@dimen/pad_10dp"
                android:textColor="@color/black" />

            <LinearLayout
                android:id="@+id/attachmentLinearLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/textViewAddAttachment"
                    style="@style/button_inner_tab"
                    android:clickable="true"
                    android:drawableLeft="@drawable/hs_add_attachment_img"
                    android:text="@string/add_attachment" />

                <TextView
                    android:id="@+id/textViewCounter"
                    android:gravity="end"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/character_counter" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/llAttachment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:visibility="gone">

                <include layout="@layout/fragment_file_attachment" />

            </LinearLayout>
        </LinearLayout>
    </android.support.v7.widget.CardView> </RelativeLayout>

这是尺寸值文件:

<resources>

    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>



    <dimen name="step_pager_tab_width">32dp</dimen>
    <dimen name="step_pager_tab_height">3dp</dimen>
    <dimen name="step_pager_tab_spacing">4dp</dimen>



    <dimen name="pad_5dp">5.0dp</dimen>
    <dimen name="pad_10dp">10.0dp</dimen>
    <dimen name="pad_15dp">15.0dp</dimen>
    <dimen name="pad_20dp">20.0dp</dimen>
    <dimen name="pad_30dp">30.0dp</dimen>
    <dimen name="pad_40dp">40.0dp</dimen>
    <dimen name="pad_100dp">100.0dp</dimen>
    <dimen name="pad_60dp">60.0dp</dimen>
    <dimen name="pad_chat_item">45.0dp</dimen>
    <dimen name="pad_chat_item1">10.0dp</dimen>
    <dimen name="txt_7sp">7.0sp</dimen>
    <dimen name="txt_8sp">8.0sp</dimen>
    <dimen name="txt_12sp">12.0sp</dimen>
    <dimen name="txt_13sp">13.0sp</dimen>
    <dimen name="txt_14sp">14.0sp</dimen>
    <dimen name="txt_15sp">15.0sp</dimen>
    <dimen name="txt_16sp">16.0sp</dimen>
    <dimen name="txt_18sp">18.0sp</dimen>
    <dimen name="txt_20sp">20.0sp</dimen>

    <dimen name="TEXT_SIZE_MEDIUM">17.0sp</dimen>
    <dimen name="TEXT_SIZE_SMALL">14.0sp</dimen>
    <dimen name="TEXT_SIZE_SMALL_MEDIUM">16.0sp</dimen>

    <dimen name="note_spacing">4dp</dimen>
    <dimen name="note_content_spacing">10dp</dimen>
    <dimen name="note_corner_radius">0dp</dimen>
    <dimen name="note_textsize">14sp</dimen>
    <dimen name="note_title_textsize">24sp</dimen>

    <dimen name="fab_spacing">0dp</dimen>
    <dimen name="fab_list_spacing">88dp</dimen>

    <dimen name="item_width">192dp</dimen>
    <dimen name="item_height">192dp</dimen>


    <dimen name="toolbar_elevation">4dp</dimen>

    <dimen name="navigation_drawer_width">300dp</dimen>

    <dimen name="top_header_bolder">0dp</dimen>

    <!-- FAB -->
    <dimen name="spacing_large">16dp</dimen>
    <dimen name="elevation_low">9dp</dimen>
    <dimen name="elevation_high">12dp</dimen>

    <!-- Header -->
    <dimen name="header_height">100dp</dimen>
    <dimen name="header_elevation">5dp</dimen>

    <!-- Header title -->
    <dimen name="title_text_size">25sp</dimen>
    <dimen name="title_left_margin">10dp</dimen>

    <!-- Header image and its background -->
    <dimen name="image_width">48dp</dimen>
    <dimen name="image_background_width">68dp</dimen>
    <dimen name="image_left_margin">26dp</dimen>
    <dimen name="image_background_left_margin">16dp</dimen>
    <dimen name="image_elevation">10dp</dimen>
    <dimen name="image_background_elevation">8dp</dimen>
    <dimen name="activity_scrollview_size">200dp</dimen>

    <!-- Inner view -->
    <dimen name="inner_padding_top">25dp</dimen>
    <dimen name="inner_padding">16dp</dimen>

    <!-- Primary button -->
    <dimen name="primary_button_width">50dp</dimen>
    <!-- 100 - 50/2 -->
    <dimen name="primary_button_margin_top">75dp</dimen>
    <!-- sqrt(2 * 50^2) -->
    <dimen name="primary_image_width">35dp</dimen>
    <!-- 100 - 35/2 -->
    <dimen name="primary_image_margin_top">82dp</dimen>
    <dimen name="primary_button_margin_right">26dp</dimen>
    <!-- 26 + (50-35)/2 -->
    <dimen name="primary_image_margin_right">32dp</dimen>
    <dimen name="primary_button_elevation">10dp</dimen>
    <dimen name="primary_image_elevation">12dp</dimen>
    <dimen name="primary_button_shadow">77dp</dimen>

    <!-- Secondary button -->
    <dimen name="secondary_button_width">40dp</dimen>
    <!-- 100 - 40/2 -->
    <dimen name="secondary_button_margin_top">80dp</dimen>
    <!-- sqrt(2 * 40^2) -->
    <dimen name="secondary_image_width">29dp</dimen>
    <!-- 100 - 29/2 -->
    <dimen name="secondary_image_margin_top">85dp</dimen>
    <dimen name="secondary_button_margin_right">100dp</dimen>
    <!-- 100 + (40-29)/2 -->
    <dimen name="secondary_image_margin_right">105dp</dimen>
    <dimen name="secondary_button_elevation">10dp</dimen>
    <dimen name="secondary_image_elevation">12dp</dimen>
    <dimen name="secondary_button_shadow">82dp</dimen>

</resources>

我尝试将layout_height值更改为“match_parent”,“fill_parent”,“match_content”,@ dimens值和plain dp值。应用程序停止,并在打开具有此xml布局的特定片段时返回此错误。

我找到了类似问题的其他答案,告诉我们使用android:weight和android:weightSum。问题是1个LinearLayout中有多个LinearLayout。我不知道我是否也会将重量分配给他们。

这是我第一次遇到这样的错误。 提前致谢, SIG

2 个答案:

答案 0 :(得分:1)

TextView

<TextView
    android:id="@+id/textViewAddAttachment"
    style="@style/button_inner_tab"
    android:clickable="true"
    android:drawableLeft="@drawable/hs_add_attachment_img"
    android:text="@string/add_attachment" />

缺少layout_widthlayout_height

如果您希望填充其中包含的LinearLayout的剩余空间,则应添加

android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"

正如this blog post中所述,layout_weight允许在布置任何固定宽度/ wrap_content元素后展开视图以填充剩余空间。

答案 1 :(得分:0)

检查您的错误。布局的第21行具有以下内容:android:layout_height="@dimen/pad_50dp"

您的dimens.xml似乎没有定义pad_50dp