Nawaf Abdu
Nawaf Abdu

Reputation: 625

Widgets inverse when I run App - android studio

I use android studio and the GUI Designer

when I run the app I see TextView in the left but i put it right in GUI Designer same with ImageView

In GUI Designer

In mobile (I've tried 2 devices with diff System Versions)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:src="@drawable/celebi"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:contentDescription="@string/celebi_picture" />
<TextView
    android:id="@+id/txt_detail"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textSize="18sp"
    android:textStyle="bold"
    android:textColor="#000000"
    android:layout_marginRight="10dp"
    android:layout_marginLeft="10dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_toEndOf="@+id/imageView"
    android:layout_alignBottom="@+id/imageView"
    android:layout_toRightOf="@+id/imageView" />

this GridLayout also inverse things !

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:id="@+id/txt_detail"
    android:layout_row="0"
    android:layout_column="1" />

<ImageView
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:id="@+id/imageView"
    android:layout_row="0"
    android:layout_column="2"
    android:src="@mipmap/ic_launcher" />

this LinearLayout same thing :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:id="@+id/txt_detail"
    android:layout_row="0"
    android:layout_column="1" />

<ImageView
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:id="@+id/imageView"
    android:layout_row="0"
    android:layout_column="2"
    android:src="@mipmap/ic_launcher" />

Upvotes: 0

Views: 55

Answers (3)

Andy Developer
Andy Developer

Reputation: 3101

Write this line in Androidmanifest.xml

<application
    android:supportsRtl="true"/>

This works for me.

Upvotes: 0

CaseyB
CaseyB

Reputation: 25058

You're using layout_alignParentRight and layout_alignParentEnd. These can be different on different versions of Android since older version don't support RTL languages. It will also change based on the whether language set on the device is RTL or not.

-=Edit=-

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/celebi"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:contentDescription="@string/celebi_picture" />

    <TextView
        android:id="@+id/txt_detail"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="18sp"
        android:textStyle="bold"
        android:textColor="#000000"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@+id/imageView" />
</RelativeLayout>

Upvotes: 1

Vijay Rajput
Vijay Rajput

Reputation: 1091

replace this code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:contentDescription="@string/app_name"
    android:src="@mipmap/ic_launcher" />

<TextView
    android:id="@+id/txt_detail"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_toEndOf="@+id/imageView"
    android:layout_toRightOf="@+id/imageView"
    android:text="asfsksdgk"
    android:textColor="#000000"
    android:textSize="18sp"
    android:textStyle="bold" />

Upvotes: 0

Related Questions