Use scrollview and adjustPan together android - android

In my manifest I have written
<activity android:name=".email"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:windowSoftInputMode="adjustPan">
</activity>
And in my layout I have written
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white" >
<ImageView
android:id="#+id/bottomImage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/ic_backdrop_wave" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:isScrollContainer="false" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText>
</EditText>
<EditText>
</EditText>
<EditText>
</EditText>
</LinearLayout>
</ScrollView>
So, When I clicked on any edit text it will not re sizes the imageview but It will also disable scroll view.
Now what I have to do to come out, I want such layout in which height of image view will not change and it will stick to align parent bottom while any soft keyboard is open, and scroll view is enable while soft key board is open.

Did you tried using
android:windowSoftInputMode="adjustResize"
This will not resize the imageview, instead it will auto adjust the screen when the keyboard popup

Here is the solution.
Make sure your Image is inside the single child inside ScrollView aligned to bottom, like this.
<ScrollView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:fillViewport="true"
android:isScrollContainer="true"
android:layout_height="0dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
....
....
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/bottom_illustration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/some_text_view"
app:layout_constraintVertical_bias="1.0"
app:srcCompat="#drawable/login_illustration" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Add the following properties to ScrollView
android:fillViewport="true"
android:isScrollContainer="true"
Add this to under your activity tag in AndroidManifest.xml
android:windowSoftInputMode="adjustResize"

Related

Text Editor keyboard overlaps with the recyclerview list

The layout has a recyclerview and a text editor at the bottom of the view. When I click the editor, the keyboard popup and overlaps with the recycerview. I want the recyclerview to be resized when the keyboard is brought up. In my Manifest file I have :
<activity android:name=".CommentActivity"
android:label="yourtime"
android:windowSoftInputMode="adjustResize">
</activity>
My layout looks like this :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:layout_alignParentBottom="true">
<EditText
android:inputType="textMultiLine"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="85"
android:id="#+id/commenteditor"
android:hint="Write a comment" />
<ImageButton
android:src="#drawable/arrow"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="15"
android:id="#+id/send"
android:background="#ffff" />
</LinearLayout>
How do I make the list scroll up or get resized when the keyboard comes up? I have tried encapsulate the recyclerview inside scrollview but that didn't work.
This is what it looks like:
I want it to look like this:
What should I do?
In your
<activity android:name=".CommentActivity"
android:label="yourtime"
android:windowSoftInputMode="adjustResize|adjustPan">
</activity>
You cannot have more than one of
adjustResize|adjustPan
the results for this are undefined.
In your case, the one you want is
<activity android:name=".CommentActivity"
android:label="yourtime"
android:windowSoftInputMode="adjustResize"/>
You can read more about this here:
activity-element
in the section that covers android:windowSoftInputMode
You should also adjust your layout so the recycler view is above the edit text container.
<android.support.v7.widget.RecyclerView
android:id="#+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linearLayout1"/>

How to set layout above soft keyboard

I have next xml layout
<ScrollView
android:id="#+id/transfer_scroller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue_500"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:orientation="vertical" ></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:orientation="vertical" ></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/tv_money_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/gray_400">
</EditText>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/transparent"
android:text="#string/btn_transfer_select_receiver"
android:textColor="#color/blue_500" />
</LinearLayout>
</LinearLayout>
when i scroll down and click on editText - open softKeyBoard and layout resize, so i can see only editText field, and I need all last LinearLayout was above keyboard so user can see btn below editText.
here is my activity in manifest:
<activity
android:name=".acitivity.Activity"
android:label="#string/title_activity"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateVisible">
</activity>
i was trying to set android:windowSoftInputMode="adjustResize" but it looks like it doesn't work with scrollView...
any idea how to fix this?
1) In AndroidManifest.xml use:
android:windowSoftInputMode="adjustResize"
2) Check this one...
3) Or you can try this one:
android:windowSoftInputMode="adjustResize|stateVisible"
If you need to open KeyBoard originally.
Hope it helps you.

Layout is getting pushed up

I have a very simple layout that i designed to achieve the tool bar at the top of the screen. I am using weights here to fit all devices. Giving like 11 to the tool bar and 89 to the content body. That will fit all screens no matter what.
Problem:
I have a scroll view inside the content body and inside that scroll view i have like 4 EditText views. When i click the last EditText to type into it my layout gets pushed up specially the tool bar for which i have to use weights.
Now please don't tell me not to use weights, just tell me how can i fix it. how can i stop the layout pushing up? Just like Gmail Client. when you are typing the header is not pushed up, stays there that you can save or send the email.
Main.xml:
<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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#ffe234"
android:layout_weight="11" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:text="Memories" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="89" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minLines="6"
android:ems="10" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
In your manifest you want you add edit or add the android:windowSoftInputMode. Then set it to adjustNothing, if you don't want the screen to adjust.
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan|adjustNothing">
</activity>
Documentation
android:windowSoftInputMode
http://developer.android.com/guide/topics/manifest/activity-element.html
adjustNothing 0x30 Don't resize or pan the window to make room for the soft input area; the window is never adjusted for it.
http://developer.android.com/reference/android/R.attr.html#windowSoftInputMode
Please use weight ="0.11" and weight ="0.89"
instead of
weight ="11" amd weight ="89" in your layout.
The layout is pushing up because scroll view adjusts to the entire screen when input method appears.
Try using ScrollView's property isScrollContainer by setting it to false.
It should look like the following:
...
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="false" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minLines="6"
android:ems="10" />
</LinearLayout>
</ScrollView>
...
If this does not help consider setting proper windowSofInputMode in your activity in AndroidManifest.xml.

Android, prevent button aligned at bottom in relative layout from going up when doing input in edittext

I have created a relative layout with 3 listviews. At top I have a editText field. In the middle there is a scrollview that fills upp all left-over space. At the bottom I have placed a button. The thing is, when I do an input in the editText field, the keyboard shows up and then the button is moved and placed ontop of the keyboard. It seems like the button allways sticks to the bottom of the view that is "left", but I want it to remain at the bottom of the original window.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/ll_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<TextView
android:id="#+id/tv_course_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_view_course_name"
android:textStyle="bold" />
<EditText
android:id="#+id/et_course_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_save_course_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="saveCourse"
android:text="#string/button_save_course" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_course_table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/ll_save_course_button"
android:layout_below="#id/ll_name" >
</LinearLayout>
</RelativeLayout>
Inside your manifest file,
<activity
android:name=".HomeActivity"
android:windowSoftInputMode="stateHidden|adjustPan" >
NOTE:
here,I have used HomeActivity,you need to specify the activity name in which you are setting the above layout xml file.
Try this:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="saveCourse"
android:gravity="bottom"
android:text="#string/button_save_course" />
or use this
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

soft keyboard covers edittexts, scroll view doesnt work

I have few editText in ScrollView. If there are many editTexts, and they exceed the display, everything works fine, but if they doesnt, and soft keyboard is opened, I cant scroll it(keyboard covers few of them). My layout:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
Any suggestions?
I added this field in the ScrollView tag:
android:isScrollContainer="false"
You can use windowSoftInputMode attribute for your activity and set it to "adjustResize". This will make room for your soft keyboard.
<activity android:windowSoftInputMode="adjustResize" />
You may need to change the "windowSoftInputMode" for the activity in your manifest file:
android:windowSoftInputMode="adjustResize"
I would try that.

Categories

Resources