简体   繁体   中英

Items move on top of each other android

I have a screen with 5 edittext, 5 buttons which appears correctly as in you can see the screenshot 在此输入图像描述

when i input text the items move on top of each other like in second screenshot, how can i fix this? 在此输入图像描述

here is my xml code

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

 <ListView
    android:id="@+id/listItems"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/btnGoHome" >

</ListView>

<Button
    android:id="@+id/btnSaveList"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="Save" />

<EditText
    android:id="@+id/saveList"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/btnSaveList"
    android:layout_toLeftOf="@+id/btnSaveList"
    android:ems="10"
    android:hint="Create Shopping List" />

<Button
    android:id="@+id/btnViewItems2"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/btnGoHome"
    android:layout_alignBottom="@+id/btnGoHome"
    android:layout_alignParentRight="true"
    android:layout_marginRight="20dp"
    android:text="View Items" />

<Button
    android:id="@+id/btnGoToShop2"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/btnAddItem"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="16dp"
    android:text="Go To Shop" />

<Button
    android:id="@+id/btnGoHome"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/btnGoToShop2"
    android:layout_alignBottom="@+id/btnGoToShop2"
    android:layout_centerHorizontal="true"
    android:text="Home" />

<Button
    android:id="@+id/btnAddItem"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/addQuantity"
    android:layout_marginTop="20dp"
    android:text="Add Item" />

<Spinner
    android:id="@+id/spShoppingList"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/addItem"
    android:layout_alignRight="@+id/btnViewItems2"
    android:layout_below="@+id/btnSaveList"
    android:layout_marginTop="14dp"
    android:ems="10" />

<EditText
    android:id="@+id/addShop"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/addQuantity"
    android:layout_alignLeft="@+id/addQuantity"
    android:layout_marginBottom="18dp"
    android:ems="10"
    android:hint="Add Shop" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/addItem"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/addShop"
    android:layout_alignLeft="@+id/addShop"
    android:layout_marginBottom="15dp"
    android:ems="10"
    android:hint="Add Item" />

<EditText
    android:id="@+id/addQuantity"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:ems="10"
    android:hint="Quantity" />

</RelativeLayout>

From project manifest, inside your activity tag, add code:

For keyboard to be visible on start

android:windowSoftInputMode="stateVisible|adjustPan"

For keyboard to be hidden on start

android:windowSoftInputMode="stateHidden|adjustPan"

Try adding the following for your activity in Manifest (for all those activities where you have this problem):

android:windowSoftInputMode="adjustPan"

eg:

<activity
   android:label="@string/app_name"
   android:name=".MainActivity" android:windowSoftInputMode="adjustPan">
   <intent-filter >
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>

For more details go here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM