当ConstraintLayout膨胀时,您必须提供layout_width属性

时间:2018-06-03 23:31:01

标签: android android-constraintlayout

以下XML文件会被夸大,我不知道为什么我会收到错误。这是XML文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="20dp"
    android:paddingRight="20dp">

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/overseas_broker_sell_avatar"
        android:layout_width="108dp"
        android:layout_height="108dp"
        android:layout_marginTop="15dp"
        android:contentDescription="@null"
        app:layout_constraintStart_toStartOf="parent"
        fresco:actualImageScaleType="centerCrop" />

    <TextView
        android:id="@+id/overseas_broker_sell_company_title"
        style="@style/overseasAgentTitle"
        android:layout_width="wrap_content"
        android:layout_height="15dp"
        android:layout_marginLeft="10dp"
        android:layout_marginStart="10dp"
        android:text="海外代理公司"
        app:layout_constraintStart_toEndOf="@+id/overseas_broker_sell_avatar"
        app:layout_constraintTop_toTopOf="@+id/overseas_broker_sell_avatar" />

    <TextView
        android:id="@+id/overseas_broker_sell_company_value"
        style="@style/overseasAgentDescribe"
        android:layout_width="0dp"
        android:layout_height="15dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/overseas_broker_sell_company_title"
        app:layout_constraintTop_toBottomOf="@+id/overseas_broker_sell_company_title"
        tools:text="Philippine Boracay Blue Water111111111" />

    <TextView
        android:id="@+id/overseas_broker_sell_presenter_title"
        style="@style/overseasAgentTitle"
        android:layout_width="wrap_content"
        android:layout_height="15dp"
        android:text="海外置业代表"
        app:layout_constraintStart_toStartOf="@+id/overseas_broker_sell_company_value"
        app:layout_constraintTop_toBottomOf="@+id/overseas_broker_sell_company_value" />

    <TextView
        android:id="@+id/overseas_broker_sell_presenter_value"
        style="@style/overseasAgentDescribe"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:width="0dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/overseas_broker_sell_presenter_title"
        app:layout_constraintTop_toBottomOf="@+id/overseas_broker_sell_presenter_title"
        tools:text="AddressAddressAddressAddressAddressAddress" />

    <TextView
        android:id="@+id/overseas_broker_sell_phone_title"
        style="@style/overseasAgentTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="海外代理电话"
        app:layout_constraintStart_toStartOf="@+id/overseas_broker_sell_presenter_value"
        app:layout_constraintTop_toBottomOf="@+id/overseas_broker_sell_presenter_value" />

    <TextView
        android:id="@+id/overseas_broker_sell_phone_value"
        style="@style/overseasAgentDescribe"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="@+id/overseas_broker_sell_phone_title"
        app:layout_constraintTop_toBottomOf="@+id/overseas_broker_sell_phone_title"
        tools:text="+39 714809471480947007148094700700" />


</android.support.constraint.ConstraintLayout>

这是logcat错误。

line #31: You must supply a layout_width attribute.
    Caused by: java.lang.UnsupportedOperationException: Binary XML file line #31: You must supply a layout_width attribute.
        at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:767)
        at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:7245)
        at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:7427)
        at android.support.constraint.ConstraintLayout$LayoutParams.<init>(ConstraintLayout.java:2102)
        at android.support.constraint.ConstraintLayout.generateLayoutParams(ConstraintLayout.java:1536)
        at android.support.constraint.ConstraintLayout.generateLayoutParams(ConstraintLayout.java:449)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:860)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)

我确信正是这个约束导致了问题,因为#31错误中指示的行号正好是声明此textView layout_width的行; textView layout_width就在那里,那抱怨什么呢?还是有一些其他的理由来限制拉出来吗?

提前致谢!

1 个答案:

答案 0 :(得分:0)

执行此操作:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="expandableItemStyle">@style/ExpandableItemStyle</item>
</style>

<style name="ExpandableItemStyle">
<item name="android:layout_height">@dimen/item_size</item>
<item name="android:layout_width">@dimen/item_size</item>
<item name="android:background">@drawable/bg_item_with_title</item>
<item name="android:layout_margin">@dimen/item_margin</item>
<item name="android:textColor">@color/gray</item>
<item name="android:textSize">@dimen/item_text_size</item>
</style>

它可以帮助你