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

查看:118
本文介绍了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.

这是我经过测试的代码示例

Here's my example of tested code

            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天全站免登陆