微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – PercentRelativeLayout – layout_width缺少警告

我正在从支持库中尝试PercentRelativeLayout,而 the docs只是要求我指定一个app:layout_widthPercent属性.但是,当我这样做时,Android Studio会给我一个红色警告,说layout_width未指定.

除了抑制警告之外,还有办法解决这个问题吗?

例如:

<android.support.percent.PercentRelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/expiry_month_wrapper"
            app:layout_widthPercent="25%"
            android:layout_height="wrap_content">
            <EditText
                android:id="@+id/expiry_month_editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:maxLength="2"
                android:hint="@string/month"
                android:focusable="true"
                android:inputType="number"/>
        </android.support.design.widget.TextInputLayout>

      <!-- more TextInputLayout fields -->

    </android.support.percent.PercentRelativeLayout>

TextInputLayout上给出的警告.

解决方法

我意识到这是一个老问题 – 但刚刚遇到这个问题我想确保它适用于所有人:)

将视图添加到PercentRelativeLayout将在文本编辑器中引发可视错误.它甚至可能无法在屏幕上呈现.继续运行您的模拟器,它应解决可见性问题.

解决错误,只需添加android:layout_width =“0dp”只要你的widthPercent和heightPercent设置得恰当,你就不会有问题.

这是我测试代码的例子

android:text="Label label"
            android:id="@+id/btn1"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_alignParentTop="true"
            app:layout_widthPercent="50%"
            app:layout_heightPercent="30%"
            android:textSize="17sp"/>

        <Button
            android:text="Other other other"
            android:id="@+id/btn2"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_toRightOf="@id/btn1"
            app:layout_widthPercent="50%"
            app:layout_heightPercent="30%"
            android:textSize="17sp"/>

原文地址:https://www.jb51.cc/android/309411.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐