首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >当ConstraintLayout正在膨胀时,必须提供layout_width属性

当ConstraintLayout正在膨胀时,必须提供layout_width属性
EN

Stack Overflow用户
提问于 2018-06-04 07:31:01
回答 1查看 175关注 0票数 0

下面的XML文件将会膨胀,我不知道为什么会出现错误。下面是XML文件:

代码语言:javascript
复制
<?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错误。

代码语言:javascript
复制
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)

我确信是这个constraintLayout导致了问题,因为#31错误中指示的行号正是声明此textView layout_width的行;textView layout_width在那里,那么它有什么可抱怨的呢?使用constrainLayout还有其他原因吗?

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2018-06-04 12:21:40

执行此操作:

代码语言:javascript
复制
<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>

它能帮到你

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50671902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档