0

I have a very simple xml file. 6 edittexts are among themselves. When I rotate the phone, they overlap. I have the 6 edittext 1) basic editttext 2) datepicker 3)timepicker 4) timepicker 5) basic edittext 6)basic edittext

How can i fix this ?

code is below. THANK YOU SO MUCH !

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.background.finalbudyfinder.CreateCinemaActivity" >


    <EditText
        android:id="@+id/editcinematitel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="22dp"
        android:ems="10"
        android:imeOptions="actionDone"
        android:hint="Titel"
        android:inputType="textPersonName"
        android:layout_alignParentTop="true"
        android:layout_alignStart="@+id/starttime" />

    <EditText
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="false"
        android:hint="Date"
        android:layout_marginTop="26dp"
        android:ems="10"
        android:padding="15dp"
        android:layout_below="@+id/editcinematitel"
        android:layout_alignStart="@+id/editcinematitel" />

    <EditText
        android:id="@+id/starttime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="false"
        android:layout_marginTop="24dp"
        android:ems="10"
        android:hint="Start-Zeit"
        android:layout_below="@+id/date"
        android:layout_centerHorizontal="true" />

    <EditText
        android:id="@+id/endtime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="false"
        android:ems="10"
        android:hint="End-Zeit"
        android:layout_centerVertical="true"
        android:layout_alignStart="@+id/starttime" />

    <EditText
        android:id="@+id/editcinemaort"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Ort"
        android:inputType="textPersonName"
        android:layout_below="@+id/endtime"
        android:layout_alignStart="@+id/endtime"
        android:layout_marginTop="27dp" />

   <!-- <EditText
        android:id="@+id/editcinemaendzeit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Description"
        android:inputType="textPersonName"
        android:layout_above="@+id/buttoncreatecinema"
        android:layout_alignStart="@+id/editcinemaort"
        android:layout_marginBottom="26dp" />

    <EditText
        android:id="@+id/editcinemastartzeit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="119dp"
        android:ems="10"
        android:hint="Start-Zeit"
        android:layout_below="@+id/editcinematitel"
        android:layout_centerHorizontal="true" />

    <EditText
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="Select Date..."
        android:padding="15dp"
        android:textColor="#897"
        android:textColorHint="#090"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_marginBottom="25dp"
        android:layout_alignBottom="@+id/editcinemastartzeit"
        android:layout_centerHorizontal="true" /> -->

    <EditText
        android:id="@+id/editcinemadescription"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Description"
        android:inputType="textPersonName"
        android:layout_above="@+id/buttoncreatecinema"
        android:layout_alignStart="@+id/editcinemaort"
        android:layout_marginBottom="26dp" />

    <Button
        android:id="@+id/buttoncreatecinema"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="27dp"
        android:text="Create" />

</RelativeLayout>
Berkay Berabi
  • 1,933
  • 1
  • 10
  • 26

3 Answers3

1

Why r u using relative layout ? just use linear layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation ="vertical"
tools:context="com.background.finalbudyfinder.CreateCinemaActivity" >


    <EditText
        android:id="@+id/editcinematitel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="22dp"
        android:ems="10"
        android:imeOptions="actionDone"
        android:hint="Titel"
        android:inputType="textPersonName"

        android:layout_alignStart="@+id/starttime" />

    <EditText
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="false"
        android:hint="Date"
        android:layout_marginTop="26dp"
        android:ems="10"
        android:padding="15dp"

        android:layout_alignStart="@+id/editcinematitel" />

    <EditText
        android:id="@+id/starttime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="false"
        android:layout_marginTop="24dp"
        android:ems="10"
        android:hint="Start-Zeit"

         />

    <EditText
        android:id="@+id/endtime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="false"
        android:ems="10"
        android:hint="End-Zeit"
        android:layout_alignStart="@+id/starttime" />

    <EditText
        android:id="@+id/editcinemaort"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Ort"
        android:inputType="textPersonName"
        android:layout_marginTop="27dp" />

   <!-- <EditText
        android:id="@+id/editcinemaendzeit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Description"
        android:inputType="textPersonName"
        android:layout_above="@+id/buttoncreatecinema"
        android:layout_alignStart="@+id/editcinemaort"
        android:layout_marginBottom="26dp" />

    <EditText
        android:id="@+id/editcinemastartzeit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="119dp"
        android:ems="10"
        android:hint="Start-Zeit"
        android:layout_below="@+id/editcinematitel"
        android:layout_centerHorizontal="true" />

    <EditText
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="Select Date..."
        android:padding="15dp"
        android:textColor="#897"
        android:textColorHint="#090"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_marginBottom="25dp"
        android:layout_alignBottom="@+id/editcinemastartzeit"
        android:layout_centerHorizontal="true" /> -->

    <EditText
        android:id="@+id/editcinemadescription"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Description"
        android:inputType="textPersonName"

        android:layout_marginBottom="26dp" />

    <Button
        android:id="@+id/buttoncreatecinema"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_marginBottom="27dp"
        android:text="Create" />

</LinearLayout>

Hope this helps u If u have any questions u can ask

Lokesh Desai
  • 2,607
  • 16
  • 28
1

Your problem

You should do following thing to fix it:

  • change all android:layout_alignStart to android:layout_centerHorizontal="true"
  • endtime EditText :android:layout_below="@+id/starttime" rather than android:layout_centerVertical="true" then you can change margin top of it. editcinemadescription EditText do as endtime.

My Suggestion

In fact,LinearLayout is in your need.

1

Here the problem is for the edit text "starttime" you have defined center vertical attribute. So when you rotate the screen since there is not enough height to contain all controls it is overlapping each other. If you remove that center vertical attribute and specify layout below then it will be ok. Also you might need to add scroll view control in order to handle landscape mode. Also noticed you have specified align start for center horizontal all the controls. Instead of it you can just specify android:gravity="center" for the parent relative layout then you can get rid of alignstart attribute from all the child controls.

Sathyajith
  • 3,836
  • 3
  • 15
  • 28