images order change in my phone – android studio

Issue

hello i am making a checkers game in android studio and my board buttons order changes when i download it to my phone.

image from android studios emulator:

how it looks in my phone:

all lines are reversed on my phone

my xml code:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    android:layout_gravity = "center"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


        <ImageButton
            android:id="@+id/box0"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="@drawable/white"
            android:foreground="@drawable/redchecker"
            tools:ignore="SpeakableTextPresentCheck" />

        <ImageButton
            android:id="@+id/box1"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="#000000"
            tools:ignore="SpeakableTextPresentCheck" />

        <ImageButton
            android:id="@+id/box2"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="@drawable/white"
            android:foreground="@drawable/redchecker"
            tools:ignore="SpeakableTextPresentCheck" />

        <ImageButton
            android:id="@+id/box3"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="#000000"
            tools:ignore="SpeakableTextPresentCheck" />

        <ImageButton
            android:id="@+id/box4"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="@drawable/white"
            android:foreground="@drawable/redchecker"
            tools:ignore="SpeakableTextPresentCheck" />

        <ImageButton
            android:id="@+id/box5"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="#000000"
            tools:ignore="SpeakableTextPresentCheck" />

        <ImageButton
            android:id="@+id/box6"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="@drawable/white"
            android:foreground="@drawable/redchecker"
            tools:ignore="SpeakableTextPresentCheck" />

        <ImageButton
            android:id="@+id/box7"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_weight="1"
            android:background="#000000"
            tools:ignore="SpeakableTextPresentCheck" />

    </LinearLayout>

ive put only one line because it just repets itself 8 times to create the board.

Solution

This is because your phone is in a RTL language. To force it to layout LTR, add android:layoutDirection="ltr" to the horizontal linear layout (all 8 of them).

Answered By – Gabe Sechan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published