Reputation: 25
When I run my android project in android emulator (Nexus 5X) it shows the correct layout which I have designed. but if I run the project in Hardware device( Samsung Galaxy J2 Prime) it shows different output.(margins are not exactly correct In Hardware device it's stick to the bottom, see the margins at bottom) 1 - Hardware device's output 2 - Emulator's output
And this is the xml code of layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".OrderStatus">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/listOrders"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="550dp">
</androidx.recyclerview.widget.RecyclerView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/listCalls"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="100dp">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</RelativeLayout>
Upvotes: 0
Views: 706
Reputation: 3268
If you want to have coordinated layouts in different devices, don't use dp sizes. It depends to size of phone. It's better to use constraint layout. See my answer for this question as an example for using constraint layout: How to prevent one activity from resizing when keyboard opens
Upvotes: 1
Reputation: 36
To make this work do the things below:
Change the size type of recyclerView from dp (density pixels) to sp (scalable pixel)
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/background" tools:context=".OrderStatus">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/listOrders"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="550sp">
</androidx.recyclerview.widget.RecyclerView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/listCalls"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="100sp">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
This change in scaling of the layout also varies from device to device.
Upvotes: 1