PercentRelativeLayout - layout_width missing warning

故事扮演 提交于 2019-12-05 08:19:45

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

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.

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

By convention, both layout_width and layout_height need to be included even when they're functionally ignored by PercentRelativeLayout's app:layout_widthPercent and app:layout_aspectRatio, respectively.

In your case, by solely using app:layout_widthPercent, just set android:layout_width to any number of density-independent pixels to get rid of the warning.

For instance: android:layout_width = "0dp"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!