PercentFrameLayout:您必须提供layout_width属性 [英] PercentFrameLayout: You must supply a layout_width attribute

查看:124
本文介绍了PercentFrameLayout:您必须提供layout_width属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 PercentFrameLayout ,但收到以下错误消息:

I try to use a PercentFrameLayout but I get this error message:

Binary XML file line #: You must supply a layout_width attribute.

这是我使用的xml:

<android.support.percent.PercentFrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        app:layout_heightPercent="50%"
        app:layout_marginLeftPercent="25%"
        app:layout_marginTopPercent="25%"
        app:layout_widthPercent="50%"/>
</android.support.percent.PercentFrameLayout>

这是错误还是我的错误?

Is this a bug or is it my mistake?

推荐答案

由于XML布局规范,仍然需要layout_widthlayout_height属性,但是在PercentFrameLayoutPercentRelativeLayout中实际上将忽略它们.

The layout_width and layout_height attributes are still required due to the XML layout specifications, but are effectively ignored in a PercentFrameLayout or PercentRelativeLayout.

您只需要将值设置为0dpwrap_content:

You just have to set the values to 0dp or wrap_content:

<ImageView
    android:layout_height="0dp"
    android:layout_width="0dp"
    app:layout_heightPercent="50%"
    app:layout_marginLeftPercent="25%"
    app:layout_marginTopPercent="25%"
    app:layout_widthPercent="50%" />

这与标准LinearLayoutlayout_weight的用法类似,在该情况下,您也必须指定layout_width.

This is similar to the usage of a standard LinearLayout with layout_weight where you have to specify a layout_width too.

这篇关于PercentFrameLayout:您必须提供layout_width属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆