0

When i rotate the screen in the emulator the text of the child elements changes its position and in my own phone its the image of the child elements that changes position ::

enter image description here

enter image description here

the parent xml :

<?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"
    android:orientation="vertical" android:layout_width="match_parent"
    android:padding="8dp"
    android:background="@android:color/holo_red_light"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/lblListHeader"
            android:layout_width="318dp"
            android:layout_height="wrap_content"
            android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
            android:textColor="@android:color/white"
            android:textSize="24dp"
            android:textStyle="bold" />

        <ImageView
            android:id="@+id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginEnd="11dp"
            android:layout_marginRight="11dp"
            app:srcCompat="@drawable/ic_action_progress" />

    </RelativeLayout>


</LinearLayout>

the child xml :

<?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"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="55dip">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/lblListItem"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginEnd="22dp"
            android:layout_marginRight="22dp"
            app:srcCompat="@android:drawable/ic_media_play" />

        <TextView
            android:id="@+id/lblListItem"
            android:layout_width="346dp"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/imageView3"
            android:layout_toStartOf="@+id/imageView3"
            android:paddingBottom="5dp"
            android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
            android:paddingTop="5dp"
            android:textColor="@android:color/white"
            android:textSize="20dp"
            android:textStyle="bold" />
    </RelativeLayout>

</LinearLayout>

I want the child element to behave the same as the parent element, any help will be apreciated. thanks.

Moun Glow
  • 61
  • 7

1 Answers1

1

One solution can be: Use two different layouts for landscape and portrait mode. For this, create a new folder named land-layout in out res directory, and place the layout file for landscape mode into it. Now when you'll rotate your device, your app will automatically set that landscape layout from that resource directory.

For more details about how to create landscape layouts, see this link: Creating Landscape layouts.

Community
  • 1
  • 1
Kaushal28
  • 5,377
  • 5
  • 41
  • 72