Question: There are a activity what I want to fill the screen in a phone
and pop up(dialog) for a tablet.

I thought I make a layout file like this, 

```
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="@dimen/main_layout_width"
  android:layout_height="match_parent">

```

and externalize the value of width as

in values/dimens.xml

```
<dimen name="tutorial_width">match_parent</dimen>

```

in values-xlarge/dimens.xml

```
<dimen name="tutorial_width">320dp</dimen>

```

But I can't representation 'match\_parent' as dimen element.
Any help? Thanks!

Answer: 
`dp` depends on the device display metrics and won't work on all devices without a set of density-specific overlays, however, `px` can be used instead.

Unfortunately, the simple rounding technique used by `TypedValue#complexToDimensionPixelSize()` only considers non-negative values:

```
final int res = (int)(f+0.5f);
if (res != 0) return res;
if (value == 0) return 0;
if (value > 0) return 1;
return -1;

```

When f (the px value) is negative, the result is usually rounded incorrectly because it always uses addition. The following pixel sizes are observed for negative `px` dimensions:

```
0px = 0.0
-1px = -1.0
-2px = -1.0
-3px = -2.0
-4px = -3.0
-5px = -4.0
...

```

I opened an AOSP issue for this method:

[TypedValue#complexToDimensionPixelSize() rounds negative dimensions incorrectly](https://code.google.com/p/android/issues/detail?id=61222&thanks=61222&ts=1382148635)

Considering this behavior, the following values will work on all devices:

```
<dimen name="match_parent">-2px</dimen>
<dimen name="wrap_content">-3px</dimen>

```

You can use -1px or -2px for match\_parent, but wrap\_content must be -3px. Either combination works on devices and emulators.

In practice, I've found that IntelliJ's Preview feature fails to render layouts when -1px is used for match\_parent, and incorrectly renders -2px as if it were "wrap\_content" when referenced by another dimension e.g. `<dimen name="my_width">@dimen/match_parent</dimen>`. I have opened an issue for IntelliJ IDEA:

[Android Preview cannot render layout\_width="-1px"](http://youtrack.jetbrains.com/issue/IDEA-115144)
According this great contribution:
<http://blog.danlew.net/2015/01/06/handling-android-resources-with-non-standard-formats/>

1. Let's try defining both match\_parent and wrap\_content without a format:

```
<item name="match_parent" type="dimen">-1</item>
<item name="wrap_content" type="dimen">-2</item>

```
2. We can reference those in any other dimension value:

```
<!-- Inside /res/values/dimens.xml -->
<dimen name="responsive_width">@dimen/match_parent</dimen>

<!-- Inside /res/values-sw800dp/dimens.xml -->
<dimen name="responsive_width">800dp</dimen> 

```

For more info visit the web page I mentioned earlier!