Incorrect layout when keyboard is shown - android

I have TextView in RelativeLayout, which works properly:
<TextView
android:id="#+id/tv_client_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/tv_label_client_out"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_in"
android:background="#drawable/border"
android:ems="10" />
Now I need to place this TextView inside of ScrollView:
<ScrollView android:id="#+id/sv_client_in"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/tv_label_client_out"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_in"
android:background="#drawable/border"
android:fillViewport="true"
>
<TextView
android:id="#+id/tv_client_in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
/>
</ScrollView>
After this change layout looks OK (first image), but when keyboard is shown, it is corrupted (second image). How can I fix this?
Full layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tv_label_client_host"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:ems="10"
android:text="#string/label_host" />
<EditText
android:id="#+id/et_client_host"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_host"
android:ems="10"
android:inputType="text"
android:lines="1" />
<TextView
android:id="#+id/tv_label_client_port"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/et_client_host"
android:ems="10"
android:text="#string/label_port" />
<EditText
android:id="#+id/et_client_port"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_port"
android:ems="10"
android:inputType="number"
android:lines="1" />
<ScrollView android:id="#+id/sv_client_in"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/tv_label_client_out"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_in"
android:background="#drawable/border"
android:fillViewport="true"
>
<TextView
android:id="#+id/tv_client_in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
/>
</ScrollView>
<Button
android:id="#+id/btn_client_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/btn_send"
android:onClick="OnBtnSendClick"
/>
<TextView
android:id="#+id/tv_label_client_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/btn_client_send"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:ems="10"
android:text="#string/label_client_out" />
<EditText
android:id="#+id/et_client_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/btn_client_send"
android:ems="10"
android:inputType="text"
android:lines="1" />
<Button
android:id="#+id/btn_client_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/et_client_port"
android:text="#string/btn_client_clear"
android:onClick="OnBtnClearClick"
/>
<Button
android:id="#+id/btn_client_disconnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/et_client_port"
android:text="#string/btn_client_disconnect"
android:onClick="OnBtnDisconnectClick"
/>
<Button
android:id="#+id/btn_client_connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_client_port"
android:layout_toLeftOf="#+id/btn_client_disconnect"
android:text="#string/btn_client_connect"
android:onClick="OnBtnConnectClick"
/>
<TextView
android:id="#+id/tv_label_client_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/btn_client_connect"
android:ems="10"
android:text="#string/label_client_in"
/>
</RelativeLayout>

This happens mainly because of the views aligning to bottom. You have aligned them to bottom, so when the keyboard pops up the bottom changes hence the Views associated with it.
Try checking your xml file.

The problem is solved by using LinearLayout.

Related

AndroidStudio Problem with Relative Layout

I have a problem with RelativeLayout. In design view I can see my Layout works perfect, but in runtime one EditText goes down from the screen.
Here is some code of my layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tvInicio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:text="#string/dialog_titulo"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvPrimero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="85dp"
android:text="#string/dialog_max"
android:textColor="#color/colorPrimary"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/etMaximo"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tvPrimero"
android:layout_alignParentEnd="true"
android:ems="10"
android:hint="#string/dialog_etMax"
android:inputType="number"
android:layout_alignParentRight="true" />
<EditText
android:id="#+id/etMinimo"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginTop="151dp"
android:ems="10"
android:hint="#string/dialog_etMin"
android:inputType="number"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/tvSegundo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/etMinimo"
android:text="#string/dialog_maxmin"
android:textColor="#color/colorPrimary"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/etMaximo2"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#+id/tvSegundo"
android:ems="10"
android:hint="#string/dialog_etMax"
android:inputType="number"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/tvTexto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/etTexto"
android:layout_alignParentStart="true"
android:text="#string/diaog_textoTitulo"
android:textColor="#color/colorPrimary"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/etTexto"
android:layout_width="193dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="180dp"
android:ems="10"
android:hint="#string/diaog_etTextoTitulo"
android:inputType="textPersonName"
android:layout_alignParentRight="true" />
<LinearLayout
android:layout_width="360dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<Button
android:id="#+id/btnCancelar"
android:layout_width="176dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="19dp"
android:layout_toLeftOf="#+id/etTexto"
android:layout_toStartOf="#+id/etTexto"
android:background="#drawable/boton_redondeado2"
android:text="#string/iniciar_sesion_cancelar"
android:textColor="#android:color/background_light" />
<Button
android:id="#+id/btnGuardar"
android:layout_width="178dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/btnCancelar"
android:layout_marginEnd="9dp"
android:layout_marginRight="9dp"
android:background="#drawable/boton_redondeado"
android:text="#string/diaog_guardar"
android:textColor="#android:color/background_light" />
</LinearLayout>
See here
Run time view look like this
Can someone help me because I'm desperate. My English is bad, so I accept edits
When using RelativeLayout, instead of using
android:layout_alignParentBottom="true"
android:layout_marginBottom="180dp"
like you are doing in the EditText with with id #+id/etTexto, you can simply write this code: android:layout_below="#id/etMaximo2"
You can even place some android:layout_marginTop if you want to add more space between the two Views.
P.S. For testing in the design view, know that you can change the dimensions of the device you're testing, so you can see in the "Preview" window what it would look like on device with different screen sizes. You can change this in the top toolbar of the preview window.
I hope this helps you! :)
Give this id to the LinearLayout:
android:id="#+id/layout"
and add this attribute to etTexto:
android:layout_above="#+id/layout"
also adjust the bottom margin as you like.
Try to delete android:layout_alignParentEnd="true" and then clean your project after the clean, run again.
Make sure that your Relative Layout is closed right after the linear ends
</LinearLayout>
</RelativeLayout>
Does it work now?
I used this xml and it worked on a Nexus 5 emulator
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tvInicio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:text="TEST"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvPrimero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="85dp"
android:text="test"
android:textColor="#color/colorPrimary"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/etMaximo"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tvPrimero"
android:layout_alignParentEnd="true"
android:ems="10"
android:hint="test"
android:inputType="number"
android:layout_alignParentRight="true" />
<EditText
android:id="#+id/etMinimo"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginTop="151dp"
android:ems="10"
android:hint="test"
android:inputType="number"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/tvSegundo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/etMinimo"
android:text="test"
android:textColor="#color/colorPrimary"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/etMaximo2"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#+id/tvSegundo"
android:ems="10"
android:hint="test"
android:inputType="number"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/tvTexto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/etTexto"
android:layout_alignParentStart="true"
android:text="test"
android:textColor="#color/colorPrimary"
android:layout_alignParentLeft="true" />
<EditText
android:id="#+id/etTexto"
android:layout_width="193dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="180dp"
android:ems="10"
android:hint="this should stay right here"
android:inputType="textPersonName"
android:layout_alignParentRight="true" />
<LinearLayout
android:layout_width="360dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<Button
android:id="#+id/btnCancelar"
android:layout_width="176dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="19dp"
android:layout_toLeftOf="#+id/etTexto"
android:layout_toStartOf="#+id/etTexto"
android:background="#color/colorPrimary"
android:text="button"
android:textColor="#android:color/background_light" />
<Button
android:id="#+id/btnGuardar"
android:layout_width="178dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/btnCancelar"
android:layout_marginEnd="9dp"
android:layout_marginRight="9dp"
android:background="#color/colorAccent"
android:text="button"
android:textColor="#android:color/background_light" />
</LinearLayout>
</RelativeLayout>
Maybe you should try putting it below EditText that is above it?
Remove
android:layout_alignParentBottom="true"
android:layout_marginBottom="180dp"
Add
android:layout_below="#+id/etMaximo2"
Result
<EditText
android:id="#+id/etTexto"
android:layout_width="193dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#+id/etMaximo2"
android:ems="10"
android:hint="#string/diaog_etTextoTitulo"
android:inputType="textPersonName"
android:layout_alignParentRight="true" />
Then set some top margin android:layout_marginTop="{some value}dp" to make it look like you want.

How to align widgets to other widgets

I am new all around design of UI inn android. and i have a 3 alignments problem in the follwoing image:
1. i would like that the rotatte laeft and right will be under the cent of the butoom "Select Photo".
2. for some reason the spinner near to the mobile edit text is not in the hegiht of the mobile edittext.
3.the "Create Account" buttom should be in the Bottom of the screen. but even when i add the following line:
android:layout_alignParentBottom="true"
nothing happend.
this is what i get in my device:
this is the xml code:
<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"
android:orientation="vertical"
android:background="#ffffffff"
tools:context="com.example.matant.gpsportclient.Controllers.Register">
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/submainLayout"
android:layout_margin="10dp"
android:layout_height="match_parent">
<ImageView
android:src="#drawable/camera"
android:layout_width="120dp"
android:layout_height="120dp"
android:id="#+id/imageViewGallery"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:background="#drawable/border"
android:padding="1dp"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_alignParentStart="true" />
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow1"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/editTextName"
android:hint="Name"
android:background="#drawable/rounded_edit_text"
android:paddingLeft="10dp"
android:layout_marginTop="160dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow2"
android:layout_below="#+id/signupRow1"
android:layout_marginTop="5dp"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editTextEmail"
android:background="#drawable/rounded_edit_text"
android:padding="10dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Email"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow3"
android:layout_marginTop="5dp"
android:layout_below="#+id/signupRow2"
android:layout_height="wrap_content">
<Spinner
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/spinnerMobile"
android:layout_marginRight="5dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:spinnerMode="dialog"
android:layout_marginBottom="5dp"
android:background="#606060"
android:layout_toLeftOf="#+id/buttonSelectImg"
android:layout_toStartOf="#+id/buttonSelectImg"
android:layout_below="#+id/editTextEmail"
android:layout_alignBottom="#+id/editTextMobile"
android:layout_weight="21.24" />
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:inputType="phone"
android:ems="10"
android:id="#+id/editTextMobile"
android:paddingLeft="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_edit_text"
android:hint="Mobile"
android:layout_weight="40.74" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow4"
android:layout_marginTop="5dp"
android:layout_below="#+id/signupRow3"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:background="#drawable/rounded_edit_text"
android:id="#+id/editTextPassword"
android:paddingLeft="5dp"
android:hint="Password"
android:fontFamily="sans-serif"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow5"
android:layout_marginTop="5dp"
android:layout_below="#+id/signupRow4"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:background="#drawable/rounded_edit_text"
android:id="#+id/editTextConfirmPass"
android:hint="Confirm Password"
android:paddingLeft="5dp"
android:fontFamily="sans-serif"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow6"
android:layout_marginTop="5dp"
android:layout_below="#+id/signupRow5"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Gender:"
android:id="#+id/textViewGender"
android:layout_gravity="left|top"
android:layout_weight="5.18" />
<Spinner
android:layout_width="129dp"
android:layout_height="30dp"
android:id="#+id/spinnerGender"
android:background="#606060"
android:layout_weight="2.84" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow7"
android:layout_marginTop="5dp"
android:layout_below="#+id/signupRow6"
android:layout_height="wrap_content"
android:baselineAligned="false">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Year of Birth:"
android:id="#+id/textViewyearOfBirth"
android:layout_weight="5.18" />
<Spinner
android:layout_width="129dp"
android:layout_height="30dp"
android:id="#+id/spinnerAge"
android:layout_marginLeft="10dp"
android:background="#606060"
android:layout_weight="3.14" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow8"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/imageViewGallery"
android:layout_below="#+id/rotateLayout"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select Photo"
android:id="#+id/buttonSelectImg"
android:layout_marginTop="5dp"
android:background="#606060"
android:textColor="#ffffffff"
android:layout_marginLeft="5dp"
android:layout_margin="10dp"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow9"
android:layout_below="#+id/signupRow8"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/imageViewGallery">
</TableRow>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="123dp"
android:background="#606060"
android:layout_marginLeft="5dp"
android:id="#+id/rotateLayout"
android:layout_toRightOf="#+id/imageViewGallery">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButtonRleftt"
android:background="#drawable/rotate_left"
android:layout_gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButtonRright"
android:background="#drawable/rotate_right"
android:onClick="rottateRight"
android:layout_gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<Button
android:id="#+id/ButtonSubmit"
android:text="Create Account"
android:layout_width="match_parent"
android:background="#606060"
android:textColor="#ffffffff"
android:layout_alignParentBottom="true"
android:layout_below="#+id/signupRow7"
android:layout_height="50dp"
android:layout_margin="5dp"
>
</Button>
</RelativeLayout>
Just set the width for both drawables to "wrap_content" and delete the weight attribute. Then add the gravity attribute to the table row like this:
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow9"
android:layout_marginTop="5dp"
android:layout_below="#+id/signupRow8"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/imageViewGallery"
android:gravity="center">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButtonRleftt"
android:src="#drawable/rotate_right"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButtonRright"
android:src="#drawable/rotate_right"
android:onClick="rottateRight"/>
</TableRow>
The easiest way is to define a static height for you tablerow and then set the height attribute for your spinner and edittext to "match_parent". Another way is to get the height of your edittext programmatically and then set the height for the spinner at runtime. I would recommend the second method, because it looks better for different devices.
You're using the wrong attribute. Try it with android:layout_alignParentTop="true" to set the View to the top.
For the
1)use a single/separate table layout and add first row as "SELECT PHOTO" using colspan attribute and for the second row add the buttons using weight Attribute.
2)Instead of using warpcontent for both of them set layout_height="50dp" or anything, such that it's similar to other widgets in terms of height.
3)use CreateAccount widget directly without a tablerow with this attribute android:layout_alignParentTop="true" such that the parent of this widget is Relativelayout.

EditText disappeared after being placed in a linear layout

When i placed my edit text into a linear layout to stop it from lagging is disappeared from the app screen and now my app crashes when its launched.(the ending of the code such as /linearLayout> is there it just wont show up on here)
old code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.trucktracker.MainActivity"
android:background="#drawable/background"
tools:ignore="MergeRootFrame">
<Button
android:id="#+id/continuebtn"
android:layout_width="match_parent"
android:layout_height="68dp"
android:layout_alignParentBottom="true"
android:onClick="clickedContinue"
android:text="#string/continue_btn"
android:textColor="#ffffff"
android:background="#drawable/btnbackreg"
android:layout_marginRight="7dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:textSize="30sp" />
<ImageView
android:id="#+id/legion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="262dp"
android:layout_marginRight="105dp"
android:contentDescription="#string/logo"
android:src="#drawable/legion" />
<TextView
android:id="#+id/question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/continuebtn"
android:layout_alignParentLeft="true"
android:layout_marginBottom="162dp"
android:text="#string/question1"
android:textSize="19sp"
android:textColor="#ffffff"
tools:context=".MainActivity" />
<EditText
android:id="#+id/Phonesignup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/continuebtn"
android:layout_alignParentLeft="true"
android:layout_marginBottom="65dp"
android:ems="10"
android:hint="#string/phonesignup"
android:inputType="phone"
android:textColorHint="#ffffff"
android:textColor="#ffffff"
android:textSize="20sp" >
</EditText>
<Spinner
android:id="#+id/optionselect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/Phonesignup"
android:layout_alignTop="#+id/question"
android:layout_marginBottom="45dp"
android:layout_marginLeft="18dp"
android:textColor="#b32017"
android:layout_toRightOf="#+id/question" />
new code:
<linearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/Phonesignup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="65dp"
android:ems="10"
android:hint="#string/phonesignup"
android:inputType="phone"
android:textColor="#ffffff"
android:textColorHint="#ffffff"
android:textSize="20sp" />
You typed the wrong tag for opening a LinearLayout. It should be a capital 'L', not a lowercase 'l'. Also, you need to set the orientation of a LinearLayout to either vertical or horizontal:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" (or horizontal)
>

android virtual keyboard changes the position of button and place it over edittext on focus

I have created an app in which there is an edittext to take input from user and below it there is an button. When the user click or focus on the edittext to input something the button position is changed by the keyboard and it overlap the edittext. I have tried the solution provided in
this answer. But it doesn't helped me
i have used this
android:windowSoftInputMode="stateVisible|adjustNothing
please someone hep....
Edit:
This is my layout xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#ffffff"
tools:context=".MyAds"
android:id="#+id/TestAd"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>
<EditText
android:id="#+id/edtLoanAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtLoanAmount"
android:layout_alignParentRight="true"
android:layout_below="#+id/txtLoanAmount"
android:ems="10"
android:background="#drawable/rounded_edittext_states"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/edtRateOfInterest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtRateOfInerest"
android:layout_alignParentRight="true"
android:layout_below="#+id/txtRateOfInerest"
android:ems="10"
android:background="#drawable/rounded_edittext_states"
android:inputType="numberDecimal" />
<TextView
android:id="#+id/txtRateOfInerest"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/edtLoanAmount"
android:layout_below="#+id/edtLoanAmount"
android:layout_marginTop="14dp"
android:text="Rate of Inerest"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtLoanAmount"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:text="Enter Loan Amount"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtLoanTenure"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/edtRateOfInterest"
android:layout_marginTop="16dp"
android:text="Loan Tenure (In Months)"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/edtLoanTenure"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/txtLoanTenure"
android:ems="10"
android:background="#drawable/rounded_edittext_states"
android:inputType="number" />
<TextView
android:id="#+id/txtEMI"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/btnCalculateEmi"
android:layout_marginTop="20dp"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnLoanAmorSchedule"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/txtEMI"
android:layout_marginTop="16dp"
android:background="#drawable/rounded_button_states"
android:text="Loan Amortization Schedule" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="125dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/initqube" />
<Button
android:id="#+id/btnCalculateEmi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingTop="3dp"
android:layout_marginTop="5dp"
android:layout_below="#id/edtLoanTenure"
android:background="#drawable/rounded_button_states"
android:text="Calculate EMI" />
<com.google.android.gms.ads.AdView
android:id="#+id/MyAdView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/imageView1"
android:layout_alignParentLeft="true"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxx" >
</com.google.android.gms.ads.AdView>
</RelativeLayout>
</ScrollView>
my issue has been solved...
<Button
android:id="#+id/btnCalculateEmi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingTop="3dp"
android:layout_marginTop="5dp"
android:layout_below="#id/edtLoanTenure"
android:background="#drawable/rounded_button_states"
android:text="Calculate EMI" />
After removing the
android:layout_centerVertical="true"
from the button property. Everything works like a charm...
Add android:windowSoftInputMode="adjustPan"
in the Android Manifest XML file for your Activity.

Background Image Stretched when taping text filed inside scroll view

I created one registration page using relative layout and applied background image to main layout. Here I used scroll view for scrolling my contents.
Problem: when I selected my textfield, background image of main relative layout stretched.
Here is my xml content:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:androidcustomfont="http://schemas.android.com/apk/res/com.cpt.realtor.activity"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="615dp" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="680dp" >
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="25dp"
android:src="#drawable/realtor_land_text" />
<EditText
android:id="#+id/editFirstName"
style="#style/activity_realtor_details_of_registration_tabletversion_for_textboxes"
android:layout_width="440dp"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:hint="#string/firstname"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editLastName"
style="#style/activity_realtor_details_of_registration_tabletversion_for_textboxes"
android:layout_width="440dp"
android:layout_height="wrap_content"
android:layout_below="#+id/editFirstName"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:hint="#string/lastname"
android:inputType="textPersonName" />
<EditText
android:id="#+id/editCompany"
style="#style/activity_realtor_details_of_registration_tabletversion_for_textboxes"
android:layout_width="440dp"
android:layout_height="wrap_content"
android:layout_below="#+id/editLastName"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:hint="#string/company"
android:inputType="text" />
<EditText
android:id="#+id/editMobile"
style="#style/activity_realtor_details_of_registration_tabletversion_for_textboxes"
android:layout_width="440dp"
android:layout_height="wrap_content"
android:layout_below="#+id/editCompany"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:hint="#string/mobile"
android:imeOptions="actionDone"
android:inputType="phone"
android:maxLength="10" />
<EditText
android:id="#+id/editEmail"
style="#style/activity_realtor_details_of_registration_tabletversion_for_textboxes"
android:layout_width="440dp"
android:layout_height="wrap_content"
android:layout_below="#+id/editMobile"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:hint="#string/email"
android:inputType="textEmailAddress" />
<Spinner
android:id="#+id/spinnerForStates"
android:layout_width="440dp"
android:layout_height="wrap_content"
android:layout_below="#+id/editEmail"
android:layout_marginLeft="40dp"
android:layout_marginTop="10dp" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spinnerForStates"
android:layout_marginLeft="50dp"
android:layout_marginTop="15dp"
android:button="#drawable/checkbox_selector"
android:text="#string/receivealert"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold" />
<com.cpt.realtor.utility.CustomFontButton
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/checkBox"
android:layout_marginLeft="180dp"
android:layout_marginTop="10dp"
android:background="#drawable/share_btn_selector"
android:text="#string/submit"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold"
androidcustomfont:customFontView="clarendon_regular.ttf" />
<TextView
android:id="#+id/textSkip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/submit"
android:layout_marginLeft="205dp"
android:layout_marginTop="8dp"
android:textSize="15sp"
android:text="#string/skip_this_step"
android:textColor="#color/white" />
<View
android:id="#+id/splitter"
android:layout_width="93dp"
android:layout_height="1dip"
android:layout_below="#+id/textSkip"
android:layout_marginLeft="210dp"
android:layout_marginTop="0dp"
android:background="#color/white" />
<View
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#+id/textSkip"
android:background="#drawable/footer" />
</RelativeLayout>
</ScrollView>
without selecting TextField:
After selecting TextField:
In my second image, the background image stretched. How can I solve this?
In your manifest write this in activity tag
android:windowSoftInputMode="stateVisible|adjustPan"

Categories

Resources