move up text view only when virtual keyboard open on android - 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>

Related

Android full screen, EditText pushes other view up

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"

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.

layout_alignParentBottom not working as expected

I am trying to get a couple of buttons to attach to the bottom of the screen.
For some reason they are attaching themselves to the previous view:
As you can see the buttons are overwriting the previous view.
This is the layout I use:
<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:text_field_element="http://schemas.android.com/apk/res-auto"
xmlns:button_element="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:orientation="vertical"
>
<LinearLayout android:id="#+id/data_entry"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<com.applicat.meuchedet.views.TextFieldElement
android:id="#+id/dental_clinics_search_screen_clinic_type_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
text_field_element:prompt="#string/dental_clinic_search_screen_dental_clinic_type_prompt"
text_field_element:initial_text="#string/dental_clinic_type_initial"
text_field_element:cursor_visible="false"
/>
<include
layout="#layout/separator_element"
/>
<com.applicat.meuchedet.views.LocationSelector
android:id="#+id/dental_clinics_location_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<include
layout="#layout/separator_element"
/>
<com.applicat.meuchedet.views.TimeSelector
android:id="#+id/dental_clinics_time_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<include
layout="#layout/separator_element"
/>
</LinearLayout>
<com.applicat.meuchedet.views.ButtonElement
android:id="#+id/dental_clinics_search_screen_search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
button_element:margin_bottom="10"
/>
<com.applicat.meuchedet.views.ClearButtonElement
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/dental_clinics_search_screen_search_button"
android:layout_alignParentBottom="true"
button_element:margin_bottom="10"
/>
</RelativeLayout>
separator_element.xml
<?xml version="1.0" encoding="UTF-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:layout_marginBottom="15dip"
android:src="#drawable/form_separator"
>
</ImageView>
============================================================================
Edit:
So, it seems that the problem is caused by the fact that the view is put into a ScrollView. We need the ScrollView due to the possibility of small screens.
For some reason it sets the size wrong or something and puts the buttons just below the fields instead of at the very bottom.

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