0

I have created a layout that is showing perfect result on graphical layout, but when i launch the application is Emulator its giving very weird look.

enter image description here

Emulator

enter image description here

I have tried margin and Padding both , but still i am not getting desired output in the emulator.

The following is my xml file. Everything is wrap in relativeLayout tag

XML File

<TextView
    android:id="@+id/successMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="14dp"
    android:gravity="center"
    android:text="Launch Complain"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_marginBottom="50pt"
     />

<Button
    android:id="@+id/btnSendMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="83dp"
    android:gravity="center"
    android:text="Send Message" />

<EditText
    android:id="@+id/userMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:ems="10"
    android:gravity="center"
    android:hint="Complain"
    android:inputType="textMultiLine" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/txtShopName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/userMessage"
    android:layout_alignLeft="@+id/userMessage"
    android:layout_marginBottom="46dp"
    android:ems="10"
    android:gravity="center"
    android:hint="Shop Name"
    android:inputType="textPersonName" />
dev90
  • 7,187
  • 15
  • 80
  • 153

2 Answers2

1

The placement of your views is currently largely based on the position relative to the center of the screen. What you need is placing your Views relative to each other.

Use the android:layout_below="@+id/item_ID" to place a view below another view, like this:

 <TextView
        android:id="@+id/successMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="14dp"
        android:gravity="center"
        android:text="Launch Complain"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_marginBottom="50pt"
         />

  <EditText
        android:id="@+id/txtShopName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/successMessage"
        android:layout_marginBottom="46dp"
        android:ems="10"
        android:gravity="center"
        android:hint="Shop Name"
        android:inputType="textPersonName" />

   <EditText
        android:id="@+id/userMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtShopName"
        android:layout_centerHorizontal="true"
        android:ems="10"
        android:gravity="center"
        android:hint="Complain"
        android:inputType="textMultiLine" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/btnSendMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/userMessage"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="83dp"
        android:gravity="center"
        android:text="Send Message" />
Frank D.
  • 1,306
  • 1
  • 13
  • 23
  • Thanks , let me try this – dev90 Aug 13 '15 at 15:13
  • i have added the above mentioned code, but nothing is changed..I am still getting the same result in emulator – dev90 Aug 13 '15 at 15:37
  • Did you remove the centerVertical parts? I added an example where I removed the code that affected vertical alignment. – Frank D. Aug 13 '15 at 15:46
  • Thanks, this added the space..but all the elements are messed up..I have uploaded the image..Kindly check http://s27.postimg.org/ocj3jduw3/space_Added.png – dev90 Aug 13 '15 at 15:55
  • Add this to the txtShopName layout: android:layout_centerHorizontal="true" – Frank D. Aug 13 '15 at 16:09
0

This is not a graphical issue, it happens due to keyboard focusing to "EditText- complain". For solving this you need to mane in Manifest file. Try this

   <activity
        android:name=".Your Activity"           
        android:label="@string/title_activity_register"          
        android:windowSoftInputMode="adjustPan" >
    </activity>

Here android:windowSoftInputMode="adjustPan" to mange your issue. For more

Community
  • 1
  • 1
Joyal
  • 414
  • 7
  • 19