Android full screen, EditText pushes other view up - android

I am working on an app and have a problem.
I have an vieww like the image below with an image and an edittext field the right position. But when i click on the edittext field and it gets the focus it pushes the other view up.
I have the full screen flag and if i dont use that it works perfect and the image keeps theire position and dont pushed up. I need that with full screen flag.
Is there someone who have some example or can help me. I have used the 'windowSoftInputMode' with all the posibles values.
Here my layout code and examples how it now works and how it needs to be.
xml layout source:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical|none" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<!-- layout for images -->
<RelativeLayout
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top" >
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/image"
android:contentDescription="TODO"/>
</RelativeLayout>
<!-- layout for edit text -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_alignTop="#id/imageview"
>
<EditText
android:id="#+id/tekstbox"
android:imeOptions="flagNoExtractUi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Here is the image how i start in the activity
When i click in the edittext field i want my view to react as below:
But when the edittext gots focus it pushes everything up like below:
Does someone know how to solve this with the fullscreen flag on?
Thanks.

User this line of code in your Manifest.xml. In the activity where the problem is occuring
<activity
android:windowSoftInputMode="stateVisible|adjustNothing">
</activity>

Add the below line in your manifest file in activity tag:
android:windowSoftInputMode="adjustResize"
and add ScrollView in your layout file like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical|none" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<!-- layout for images -->
<RelativeLayout
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top" >
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/image"
android:contentDescription="TODO"/>
</RelativeLayout>
<!-- layout for edit text -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_alignTop="#id/imageview"
>
<EditText
android:id="#+id/tekstbox"
android:imeOptions="flagNoExtractUi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>

Add the below line in your manifest file in activity tag:
android:windowSoftInputMode="adjustPan|stateHidden"

Related

Adapting component when virtual keyboard appears

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

edit text height getting decrease on click

I am having a editText and a listview in a single layout .But on clicking editText its height getting decrease like this
Before Click :
On Click :
Here is my XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent_clients_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffffff"
android:orientation="vertical" >
<EditText
android:id="#+id/search_button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5.0dip"
android:layout_weight="0.9"
android:background="#drawable/edbackground"
android:drawableLeft="#drawable/search"
android:drawablePadding="10.0dip"
android:hint="search clients"
android:textColor="#color/gray"
android:textSize="15.0dip" />
<ListView
android:id="#+id/clients_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5.0dip"
android:layout_weight="0.1"
android:background="#android:color/white" />
</LinearLayout>
Just put android:layout_height="wrap_content" instead of android:layout_height="fill_parent" and also remove android:layout_weight="0.9" to EditText
Remove weight and put wrap_content for height of EditText
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent_clients_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffffff"
android:orientation="vertical" >
<EditText
android:id="#+id/search_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"
android:drawableLeft="#drawable/ic_launcher"
android:drawablePadding="10.0dip"
android:hint="search clients"
android:textColor="#123456"
android:textSize="15.0dip" />
<ListView
android:id="#+id/clients_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5.0dip"
android:layout_weight="0.1"
android:background="#android:color/white" />
</LinearLayout>
This should work
When you click on your edittext, soft-input comes up and android adjust screen contents sometimes. This is reason your edittext is looking cropped. To prevent this, in your Manifest.xml where you have defined your activity, add following line in your Activity tag:-
android:windowSoftInputMode="adjustNothing"
This will work.

Android ScrollView not scrolling

I have solved my question. I chose to instead have a header and a footer that are always located at the bottom and top of the screen respectively. Then I created a "center content" which I enclosed within a ScrollView layout. I have updated the code below if people are interested in seeing what it now looks like.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="#FFFFFF">
<LinearLayout android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#layout/header"
android:layout_alignParentTop="true">
<ImageView android:src="#drawable/logo"
android:contentDescription="#string/logo_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"/>
</LinearLayout>
<ScrollView android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="350dip"
android:layout_below="#id/header">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dip" >
<!-- Email Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372C24"
android:text="#string/email"/>
<EditText android:id="#+id/email_field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:inputType="textEmailAddress"/>
<!-- Password Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:textColor="#372C24"
android:text="#string/password"/>
<EditText android:id="#+id/password_field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="textPassword"/>
<!-- Login button -->
<Button android:id="#+id/login_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dip"
android:text="#string/login"/>
<!-- Register button -->
<Button android:id="#+id/register_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dip"
android:text="#string/register_button"/>
</LinearLayout>
</ScrollView>
<LinearLayout android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="90dip"
android:background="#layout/footer"
android:layout_alignParentBottom="true">
</LinearLayout>
</RelativeLayout>
For me, remove android:windowSoftInputMode="adjustPan" of the <activity> tag in AndroidManifest.xml file solved the problem.
I removed this line from the AndroidManifest.xml file
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
and added this line
android:theme="#android:style/Theme.NoTitleBar"
it has both fixed my scrolling app and made my app look more visually appealing. However, I am not sure if this is the correct fix.
for me the problem was that the LinearLayout in the ScrowView had android:layout_height="wrap_content".
<ScrollView android:id="#+id/scroll_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout android:id="#+id/layout_inside"
android:layout_width="match_parent"
android:layout_height="wrap_content" --> This should not we wrap_content, but specific height.
android:orientation="vertical" >
The ScrollView is not working when used as the root element of an XML layout.
It has to be wrapped inside a LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView android:id="#+id/scroll_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout android:id="#+id/layout_inside"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
Have a fun ! !
ScrollView must have Linearlayout control as a immediate child, you have relative layout, I think that might be causing the problem.
Check this link out, also this. Look at their layout xmls..

move up text view only when virtual keyboard open on android

My xml code is here,
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/mainlayout" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/toplayout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:src="#drawable/bg" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="#+id/bottomlayout">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter value" />
</LinearLayout>
when i execute , i got like this,
after execute , when i enter the value on edit text ,the virtual keyboard is open and the entire mainlayout is scroll up, i got like this
But i except , the top layout not to scroll up , only the bottom layout or textview scroll up. i expect like this,
how to scroll only the edit view when open the virtual keyboard. ?
Try this; maybe it is useful. Adjust the manifest file
<activity
android:windowSoftInputMode="adjustResize"
android:name=".youractivity" android:label="#string/app_name" >
#Ganesh you change manifest like above your Activity code also working
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/toplayout">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<EditText
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:hint="Enter value" />
</RelativeLayout>
</LinearLayout>

Softkeyboard moves button in LinearLayout

Hi I'm designing a navigation application for as a Uni project. I'm having problems with getting the button to stay underneath the soft keyboard when it appears. I'm using LinearLayout as a frame. I've searched a lot and tried different techniques but nothing seems to work.
a picture of the problem
Here is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" />
<requestFocus />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:orientation="vertical" >
<EditText
android:id="#+id/navi_searchfield1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Current location" >
</EditText>
<ListView
android:id="#+id/navi_listview1"
android:layout_width="fill_parent"
android:layout_height="0dp">
</ListView>
<EditText
android:id="#+id/navi_searchfield2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Destination" />
<ListView
android:id="#+id/navi_listview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<Button
android:id="#+id/start_navigation"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:background="#drawable/start"
android:textColor="#ffffff"
android:text="Start navigation" />
</LinearLayout>
Add android:windowSoftInputMode="adjustPan" to your activity in AndroidManifest.xml as:
<activity
android:windowSoftInputMode="adjustPan"
.
.
.
</activity>
This will prevent SoftKeyboard from moving your button, giving you an output like:
You can use the button even though the keyboard is shown by scrolling on the screen. But I think you probably can't show the keyboard above the button because I worked with SoftKeyboard and it uses:
android:layout_alignParentBottom="true"
So, you can only keep your layout safe from being pushed by SoftKeyboard.

Categories

Resources