Android: Suppressing the warning about using px in layout xml

When working with for instance the Sony SmartWatch there is a need to specify layout for the Watch in pixels (not device pixels) – as the SmartWatch is a fixed size and not dependent of the device it is connected to. When this is done the lint verification will warn about this being a bad idea, but it is possible to suppress this warning by adding the following to the xml file:

  1. add the namespace xmlns:tools=”http://schemas.android.com/tools”
  2. and then then you can disable the px-warnings by including this in your view: tools:ignore=”PxUsage”.

Example:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/background"
>
 
    <View
        tools:ignore="PxUsage"
        android:id="@+id/smartWatchView"
        android:layout_width="128px"
        android:layout_height="128px"
        android:visibility="visible"
        android:layout_centerInParent="true" 
    />
 
</RelativeLayout>