PercentRelativeLayout - missing layout_width warning

I tried PercentRelativeLayout from the support library, and the documents just asked for the app property: layout_widthPercent. However, when I do this, Android Studio gives me red warning information that layout_width is not set.

Besides suppressing the warning, is there any way around this?

For instance:

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

Warning indicated in TextInputLayout.

+6
source share
2 answers

I understand that this is an old question, but when faced with this problem, I want to make sure that it is accessible to everyone :)

Adding a view to your PercentRelativeLayout will result in a visual error in a text editor. It may not appear even on the screen. Go ahead and run your emulator and it should solve the visibility problem.

To fix the error, just add android:layout_width="0dp" If your widthPercent and heightPercent set accordingly, you will not have a problem.

Here is my sample verified 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"/> 
+1
source

By convention, both layout_width and layout_height should be included, even if they are functionally ignored by PercentRelativeLayout: layout_widthPercent and app: layout_aspectRatio, respectively.

In your case, just using app: layout_widthPercent, just set android: layout_width to any number of pixel density independent ones to get rid of the warning.

For example: android: layout_width = "0dp"

+8
source

All Articles