Android resize one part of layout when soft keyboard displayed - android

I want to create layout which consists in normal condition from image and few EditTexts as displayed in the next image
But when user starts to enter the text I need to change the layout the next way:
Soft keyboard at the bottom of screen,
EditTexts about it but Image is resized according to the size of soft keyboard as displayed here
How can I do it?
Thanks in advance

Try this code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Also set
android:windowSoftInputMode="adjustResize"
as property to your Activity in AndroidManifest.xml

Related

Android Soft Keyboard not showing all `EditText`

First off all let me say that I've tried in the manifest android:windowSoftInputMode="adjustPan|stateHidden" and android:windowSoftInputMode="adjustResize|stateHidden" and the result is the same.
I have a layout with an Header and a Footer and in between I have an ScrollView. Inside this, I have a RelativeLayout and inside this layout, I have one EditText and a LinearLayout containing another EditText (this layout makes sense in my app).
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scroll"
android:layout_below="#+id/header"
android:fillViewport="true"
android:layout_above="#+id/footer">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="40dp">
<EditText
android:id="#+id/one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/edittextback"
android:layout_marginBottom="40dp" />
<LinearLayout
android:id="#+id/placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/one"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
android:layout_marginBottom="40dp">
<EditText
android:id="#+id/two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edittextback"
android:gravity="center"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
When I enter the activity and start entering text in the first edittext, the keyboard pops up, the scroll goes up a little so the I can see the text that I'm inserting. The problem is that the edittext is not all visible (I mean the bottom boundary). The keyboard stays just bellow the inserted text and not bellow the bottom of the edittext.
Now, since I already have the keyboard open, I scroll a bit so that I can see the top of the second edittext. When I touch the second edittext, it gains focus, and now, it automatically scrolls a bit not like the first edittext, that is, just enough to see the inserted text, but to the bottom of the edittext making the edittext all visible. This is what I want.
How can I make the behavior to be show always all the edittext?

Forcing a soft keyboard to fill width of screen

I've created a simple pinnumber keyboard using this post as a basis for my program
http://www.fampennings.nl/maarten/android/09keyboard/index.htm
My problem arises with that the soft keyboard will not fill the entire width of my screen, even though I am using the %p dimensions.
Is there away to force my keyboard view so that it automaticly fills the width of the screen? Trying to use match/fill parents has not worked.
Is there away to force my keyboard view so that it automaticly fills the width of the screen? Trying to use match/fill parents has not worked.>
Can you post your xml? Have you checked through it thoroughly to make sure that you are using match_parent in every location that relates to the width of the keyboard?
I encounter the same issue.One solution is add two flexible spacers at left and right with the same background color as the keyboard.
The layout is something as below:
<LinearLayout
android:orientation="horizontal"
android:background="#color/grey"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:background="#color/grey"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"/>
<KeyboardView
android:id="#+id/keyboard_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/grey"
android:focusable="true"
android:focusableInTouchMode="true"
android:keyBackground="#drawable/btn_keyboard_key"
android:keyTextColor="#color/black"
android:keyTextSize="28dp"
android:labelTextSize="20dp"
android:shadowColor="#color/grey"
android:shadowRadius="0.0"
android:visibility="gone" />
<View
android:background="#color/"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"/>
</LinearLayout>

Why does the visibility "gone" for button not work with scrollviews?

I have a layout like:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:scrollbars="vertical"
android:layout_weight="1">
<-- A relative layout that contains a lot of edit text fields and a few text views at the bottom that cover up the screen-->
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="something"
android:layout_weight="0"
android:visibility="gone"/>
</LinearLayout>
and what i want to do is just achieve the effect that when the keyboard pops up from tapping on any EditView inside the ScrollView, the button at the bottom should NOT cover up any text views, because it is in the gone state. but right now, whenever i tap on any of the EditText fields, it seems to be covering up some of the text views that i have.
why is the screen rendered such that it designates space for the gone button i have at the bottom?
Try adding the following to the activity tag in your manifest.
android:windowSoftInputMode="adjustNothing"

Android layout design: image above form above button. When the keyboard appears my layout is screwed

In my application I want to have a layout like this:
I did it with a Relative Layout holding an ImageView, TableLayout and a Button. The problem is that when I open the keyboard to modify a EditText the keyboard is on top of the EditText, so the user can't see what he is writing. I want the layout to be like this when the keyboard is shown:
The user should be able to scroll up the view to see the whole image while the keyboard is shown, even if he doesn't see the EditText then, because he wants to copy some data of the image into the EditTexts. I tried to do it like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/buttonEditStop"
android:padding="10dip" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/stopImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:clickable="true"
android:contentDescription="#string/entry_img"
android:onClick="ImageClick" />
<TableLayout
android:id="#+id/formLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/stopImg"
android:layout_marginRight="10dp" >
...
</TableLayout>
</RelativeLayout>
</ScrollView>
<ImageButton
android:id="#+id/buttonEditStop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/edit_stop"
android:onClick="EditButtonClicked"
android:src="#drawable/ic_menu_edit" />
Using this code my whole layout is screwed. I see the form on top of the image, followed by a ImageButton with the image that should be seen in the imageView.
Anyone knows how I can get a layout like the one I want?
Thanks!
To avoid the EditText to be overlapped I had to use
android:windowSoftInputMode="adjustPan"
in my manifest.

Soft-keyboard appears every time layout becomes visible

I have two layouts within a fragment that I switch back and forth between by making one invisible and the other visible and visa versa. When the layout that contains an EditText becomes visible the soft keyboard automatically pops up. I have used the following in the manifest but it didn't help.
android:windowSoftInputMode="stateUnchanged"
I never explicitly request focus on the EditText and have even tried requesting focus on something else to no avail.
<?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:id="#+id/container">
<LinearLayout android:id="#+id/dial_pad_ll"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:layout_centerInParent="true"
android:background="#1E1E1E" android:layout_marginLeft="20dp" android:layout_marginRight="20dp">
<EditText android:layout_height="wrap_content" android:id="#+id/search_et"
android:layout_width="match_parent" android:layout_alignParentTop="true"
android:layout_marginTop="20dp" android:layout_marginBottom="10dp" >
</EditText>
<!-- Other widgets here -->
</LinearLayout>
<!-- Other Layout Here -->
</RelativeLayout>
Anyone know how to prevent this? Thanks.
Edit: I should also have mentioned that this doesn't happen the first time. I open layout 1 with the edit text, make it invisible, make it visible again, then the keyboard pops up.
try adding this to your activity.
this.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Categories

Resources