Ashraf Mohamed
Ashraf Mohamed

Reputation: 141

Why there is a difference between my app in a real device and the layout preview in android studio

app description :- simple app with listView (orientation : horizontal)

the problem is :- when i run the app on a real device , i found that all views direction get reversed

this is an item on android studio:- app preview on android studio

but when it run on a real device it look like this app on a real device

this is my layout (item.xml) code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/item_layout_id"
    android:padding="20dp">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/mag_id"
        android:layout_weight="1"
        android:text="7.1"
        android:textColor="#302f2f"
        android:textSize="18sp"/>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/country_id"
        android:layout_weight="1"
        android:text="Egypt"
        android:textColor="#302f2f"
        android:textSize="18sp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/date_id"
        android:layout_weight="1"
        android:text="July 21,2018"
        android:textColor="#302f2f"
        android:textSize="18sp"/>

</LinearLayout>

i want to display the same design from android studio preview on the real device with the same view direction.

so what is the problem and how i can fix this.

Upvotes: 0

Views: 580

Answers (2)

sachinparmarr
sachinparmarr

Reputation: 11

This is due to difference between the screen size and display resolution, the layout that you're designing in the studio might look good on that exact screen size or resolution that you've selected in the layout editor, but that might not be the case for every device, your device in this case. You can refer this thread for more detailed solution to your problem

Upvotes: 1

Pouya Danesh
Pouya Danesh

Reputation: 1627

you should check two or three things:

1- is your ListView parent layout has layoutDirection in XML?

2- have you called the method getWindow().setLayoutDirection(LayoutDirection.RTL) any where in your code?

3- if your list activity or fragment does not have number 2 then you should check your adapter class to see if there is any code written about ItemView direction.

4- if non of this is relevant for you please try changing preview android version and preview size.

hope this helps.

Upvotes: 0

Related Questions