This question already has answers here:
Android soft keyboard covers EditText field
(15 answers)
Closed 7 years ago.
I have a Fragment that contains a ListView to which I add three EditText's to and one Spinner when I select the second EditText the keyboard shows as expected but I cannot scroll the list view to the last two remaining elements in the list view while the keyboard is visible.
It's almost as though the list view is not recognizing that the soft-keyboard is visible the last two remaining elements are still behind the soft-keyboard.
Below is screenshots and XML of the views in question.
AndroidManifest:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan">
List view:
<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=".MainActivity$PlaceholderFragment"
android:background="#color/generic_grey">
<ListView
android:id="#+id/form_base_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#null"
android:dividerHeight="0dp"
android:descendantFocusability="afterDescendants"
/>
</RelativeLayout>
Multiline View:
<?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="wrap_content"
android:background="#color/white"
android:paddingBottom="5dp">
<TextView
android:id="#+id/form_multi_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/testing"
android:padding="10dp"/>
<EditText
android:id="#+id/form_multi_edit"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_below="#+id/form_multi_txt"
android:layout_marginLeft="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:background="#drawable/edit_text_background"
android:layout_toLeftOf="#+id/form_multi_info_btn"
android:layout_toStartOf="#+id/form_multi_info_btn"
android:inputType="textMultiLine"/>
<ImageButton
android:id="#+id/form_multi_info_btn"
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="fitStart"
android:src="#drawable/form_row_info"
android:background="#android:color/transparent"
android:layout_below="#+id/form_multi_txt"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"/>
</RelativeLayout>
Spinner:
<?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="wrap_content"
android:background="#color/white"
android:paddingBottom="5dp">
<TextView
android:id="#+id/form_select_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/testing"
android:padding="10dp"/>
<Spinner
android:id="#+id/form_select_spinner"
android:layout_width="fill_parent"
android:layout_height="44dp"
android:layout_below="#+id/form_select_txt"
android:layout_marginLeft="5dp"
android:spinnerMode="dialog"
android:layout_toLeftOf="#+id/form_select_info_btn"
android:layout_toStartOf="#+id/form_select_info_btn"
android:background="#android:drawable/btn_dropdown"
/>
<ImageButton
android:id="#+id/form_select_info_btn"
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="fitStart"
android:src="#drawable/form_row_info"
android:background="#android:color/transparent"
android:layout_below="#+id/form_select_txt"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"/>
</RelativeLayout>
The view within the spinner:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textViewSpinnerItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
style="#style/SpinnerTextViewItem"
/>
Complete View:
View with Keyboard: (cannot scroll to view last two elements)
Put the all Tags in a Realtive Layout and the Relative Layout in ScrollView. As ScrollView takes Only One Child.
<?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="wrap_content"
android:background="#color/white"
android:paddingBottom="5dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/form_multi_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/testing"
android:padding="10dp"/>
<EditText
android:id="#+id/form_multi_edit"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_below="#+id/form_multi_txt"
android:layout_marginLeft="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:background="#drawable/edit_text_background"
android:layout_toLeftOf="#+id/form_multi_info_btn"
android:layout_toStartOf="#+id/form_multi_info_btn"
android:inputType="textMultiLine"/>
<ImageButton
android:id="#+id/form_multi_info_btn"
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="fitStart"
android:src="#drawable/form_row_info"
android:background="#android:color/transparent"
android:layout_below="#+id/form_multi_txt"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
It's because your activity layout needs to be adjusted once soft keyboard opens and you got this not set. What you need to do is to edit your Manifest and add
android:windowSoftInputMode="adjustResize"
to right <activity> tag. Here's Handling Input Method Visibility chapter in the docs, you may want to read to see what behaviours can you set with windowSoftInputMode
Related
I have the following layout, probably with many many errors:
<FrameLayout
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"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc"
android:layout_marginBottom = "0dp">
<ScrollView android:id="#+id/ScrollView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<GridLayout
android:id="#+id/grid"
android:layout_margin="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#+id/new_cancel"
android:alignmentMode="alignBounds"
android:columnCount="10"
android:columnOrderPreserved="false"
android:useDefaultMargins="true">
<TextView
// TextViews and EditText etc...
// ...
</GridLayout>
</ScrollView>
<Button
android:id="#+id/new_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#color/colorPrimaryDark"
android:text="Cancel"
android:layout_margin="5dp"
/>
<Button
android:id="#+id/new_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:background="#color/colorPrimaryLight"
android:text="Ok"
android:layout_margin="5dp"
/>
</RelativeLayout>
</FrameLayout>
The main part (GridLayout) contains several input fields to input text, numbers etc. But when I click on such an input field the touch-keypad opens and overlaps part of my input fields! Although this ViewGroup is placed inside a ScrollView, I am not able to scroll it!
How to change the layout so I can scroll the stuff inside the GridLayout...?
In AndroidManifest write
<activity
android:name="<yourpackage>.MainActivity"
...
android:windowSoftInputMode="adjustResize" />
This will resize your activity when keyboard opens
Remove scrollViewand add this to the onCreate of your activity
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
This will resize the activity's on keyboard open
I'm creating an app that gets some values, you click in a button and it returns some other values and this views are distributed in 2 subLayouts of a bigger vertical LinearLayout like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="0.4">
<EditText
android:layout_width="70dp"
android:layout_height="wrap_content"
android:inputType="number"
android:id="#+id/number1" />
<EditText
android:layout_width="70dp"
android:layout_height="wrap_content"
android:inputType="number"
android:id="#+id/number2"
android:layout_below="#+id/number1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calc!"
android:id="#+id/calcButton"
android:layout_below="#+id/number2"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="0.6"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Answer"
android:id="#+id/Answer" />
</RelativeLayout>
</LinearLayout>
My problem is that when I click on my EditText and the keyboard appears the answer's TextView goes up with the keyboard and "overrides" my button (the entire RelativeLayout follows the keyboard), there's a way of setting the RelativeLayout fixed so that it stays where it is mean to be?
Here what is happening:
There's a way of fixing that RelativeLayout?
Try setting android:windowSoftInputMode="adjustPan" for the activity in Android Manifest file.
I'm designing a simple login activity. I've used the following xml layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:layout_margin="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My application title"
android:textSize="30sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center_vertical"
android:layout_margin="15dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:layout_marginTop="15dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Login"/>
</LinearLayout>
</LinearLayout>
And I've obtained this result:
But If the focus is on the first EditText I obtain this:
and If the focus is on the second EdiText the result is the follwoing:
Considering I've used the following line in the Manifest, for my activity:
android:windowSoftInputMode="adjustPan|adjustResize"
I want that when the virtual keyboard appears, the two edittext, the button and the textview are visible and correctly centered in the available screen.
What I have to change in my code?
NOTE: I've the same result If I remove the line in the manifest:
android:windowSoftInputMode="adjustPan|adjustResize"
You can replace the parent LinearLayout to a ScrollView :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout ...>
....
....
</LinearLayout>
</ScrollView>
try this, it works for some of my apk !
Edit : sorry didn't see about center the text automaticaly, so with this you can adjust manually your editext to center with swipe your finger.. hope that will help
I have a fragment with a listview and an edittext.
When the edittext gains focus all the layout except the edittext turns black for one second.
If I hold the edittext clicked then the surrounding layout stays black until I scroll the list, or touch the screen, it only happens on Jelly Bean 4.1.2.
Here is my xml:
<?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"
android:background="#null"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/search_layout"
android:layout_width="fill_parent"
android:layout_height="49.33dp"
android:background="#color/grey">
<EditText
android:id="#+id/search_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:background="#drawable/searchbox"
android:drawableLeft="#drawable/search_icon"
android:ems="8"
android:hint="#string/search_hint"
android:maxLines="1"
android:padding="3dp"
android:paddingLeft="15dp"
android:paddingRight="25dp"
android:singleLine="true" />
</RelativeLayout>
<com.emilsjolander.components.stickylistheaders.StickyListHeadersListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/search_layout"
android:divider="#color/light_blue"
android:dividerHeight="0.67dp" />
</RelativeLayout>
What can be the causes for that behavior ?
Add the following line to your listview(in xml) and try..
android:cacheColorHint="#00000000"
Hope it works!!
Good day, I have an Activity which contains 4 fragments. The Activity has a footer which I use to switch between these fragment views. Now in one of my fragments, i have some widgets and the last widget is a ListView. The trouble am having is, the last 2 entries in the Listview are not displaying correctly! they are obscured by the footer. I have set my LayoutParameters for both the width and height of the Listview to FILL_PARENT. but its not working. Any idea how i can solve this? Thanks in advance.
My Layout is :
for the fragment:
<?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"
android:orientation="vertical">
<Button android:id="#+id/line_button_id" android:layout_width="160dp"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:layout_marginLeft="5dp" android:focusable="true"
android:layout_marginTop="8dp" android:text="#string/line_graph" android:background="#drawable/temp_left_button" />
<Button android:id="#+id/bar_button_id" android:layout_width="160dp"
android:layout_height="wrap_content" android:layout_alignBaseline="#+id/line_button_id"
android:layout_alignBottom="#+id/line_button_id" android:focusable="true"
android:layout_alignParentRight="true" android:layout_marginRight="5dp"
android:text="#string/bar_graph" android:background="#drawable/temp_right_button"></Button>"
<FrameLayout
android:id="#+id/graph_framelayout_id"
android:layout_width="fill_parent"
android:layout_height="280dp"
android:layout_below="#id/line_button_id"
android:padding="4dp"
android:layout_margin="4dp"
android:background="#drawable/rounded_date_filter">
</FrameLayout>
<!-- first cell information, dashboard -->
<LinearLayout
android:id="#+id/row1_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_below="#id/graph_framelayout_id"
android:orientation="horizontal"
android:clickable="true"
android:background="#drawable/rounded_table_row">
<TextView
android:id="#+id/dashboard_datefrom_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:text="01 may 2012"/>
<ImageView
android:id="#+id/dashboard_image_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/ic_action_search"/>
<TextView
android:id="#+id/dashboard_dateto_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:text="01 sept 2012"/>
</LinearLayout>
<!-- accounts overview listview -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row1_id"
android:layout_margin="4dp"
android:orientation="vertical"
android:background="#drawable/rounded_date_filter">
<TextView
android:id="#+id/list_text_header_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="#string/data_grid_text_header_day"
android:background="#drawable/text_header">
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
</RelativeLayout>
and for the Activity i have this:
<
?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"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/fragment_container_id"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
<include layout="#layout/footer"></include>"
</RelativeLayout>
i replace the fragments with in the framelayout of the Activity
What Layout are you using in your Fragment, this surely won't happen if you use RelativeLayout and set above attribute to your ListView like this :
Try to add this into FrameLayout in your Activity layout.
android:layout_above="#+id/footer"