PercentRelativeLayout - layout_width 缺少警告 [英] PercentRelativeLayout - layout_width missing warning

查看:28
本文介绍了PercentRelativeLayout - layout_width 缺少警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试支持库中的 PercentRelativeLayout,文档让我指定一个 app:layout_widthPercent 属性.但是,当我这样做时,Android Studio 会给我一个红色警告,说 layout_width 未指定.

I'm trying out PercentRelativeLayout from the support library, and the docs just ask me to specify an app:layout_widthPercent property. However, when I do that, Android Studio gives me a red warn saying that the layout_width is unspecified.

除了取消警告之外,还有什么办法可以解决这个问题吗?

Other than suppressing the warning, is there a way around this?

例如:

    <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 给出警告.

Warning given on TextInputLayout.

推荐答案

我意识到这是一个老问题 - 但刚刚遇到这个问题我想确保每个人都可以使用 :)

I realize this is an old question - but having just encountered this problem I want to make sure it's available for everyone :)

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

Adding a view to your PercentRelativeLayout will throw a visual error in the text editor. It may fail to render on the screen even. Go ahead and run your emulator and it should resolve the visibility issue.

要解决该错误,只需添加 android:layout_width="0dp" 只要您的 widthPercentheightPercent 设置适当,您就可以没有问题.

To resolve the error just add android:layout_width="0dp" So long as your widthPercent and heightPercent are set appropriately you'll not have an issue.

这是我的测试代码示例

            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"/>

这篇关于PercentRelativeLayout - layout_width 缺少警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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