I am developing an application using density criteria, but when I compare my layout in those screens Galaxy Nexus (720x1280) and Nexus 4 (768x1280), the former is fine and in the latter there is a white space on the left side.
I use dp to scale the layout and the 2 layout have the same density (xhdpi).
So how can I design different layout with the same density and screen size?
Here is a sample code to create an xhdpi layout an use Android Studio preview in these 2 phones to see the next picture.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="dimx"
android:layout_height="dimy"
android:background="@android:color/black"/>
</LinearLayout>
dimens file in the xhdpi folder
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="dimx">360dp</dimen>
<dimen name="dimy">512dp</dimen>
</resources>
dimens file in the other folder
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="@dimen/dimx">0dp</dimen>
<dimen name="@dimen/dimy">0dp</dimen>
You have a problem in your xml is android:layout_width="@dimen/dimx"
and android:layout_height="@dimen/dimy"
Edit: Google Nexus and Nexus 4 have different screen width and you use hardcoded dimensions, this is the main problem. To avoid any future problem use relative value instead of hardcoded value, in your case setting match_parent will solve your issue.
Hope it helps!!