I have a fullscreen activity with a fullscreen ImageView in the background. I have an EditText placed in the middle of the screen using gravity:center
. When the keyboard opens I want the EditText to move up as shown in the picture below so that the whole EditText is always visible. I have attempted using android:windowSoftInputMode="stateVisible|adjustResize"
however the problem with this is that my Image in the background is also resized which is not desirable. Furthermore, since the gravity is set to center this results in there being a gap between the EditText and keyboard so that it is still in the center. I have tried using a scrollView however I did not know how to obtain the position at which the keyboard ends so that I can move my EditText to that position. I have also tried adjustPan
however this had no effect since the EditText is 200dp
in height and the gravity is set to center so the user always starts typing in the middle of the EditText which is still visible.
XML
<FrameLayout
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">
<FrameLayout
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:id="@+id/picturedisplay"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_gravity="center"
android:layout_height="200dp"
android:weightSum="100"
android:visibility="gone"
android:id="@+id/pic_layout"
android:orientation="vertical"
android:background="#9945D199"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="0dp"
android:hint="Enter text here..."
android:textColor="#FFFFFF"
android:maxLength="250"
android:gravity="center"
android:imeOptions="flagNoExtractUi"
android:id="@+id/pic_textbox"
android:layout_weight="90"/>
<TextView
android:layout_width="40dp"
android:layout_height="0px"
android:text="200"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_weight="10"
android:id="@+id/char_rem_view"
android:layout_gravity="end"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgClose"
android:layout_gravity="right|bottom"
android:text="Flip Cam"
android:padding="20dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/snap"
android:text="Capture"
android:layout_gravity="center|bottom"
android:padding="20dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Flash"
android:visibility="visible"
android:id="@+id/imgOpen"
android:layout_gravity="left|bottom"
android:padding="20dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/addText"
android:layout_gravity="right|bottom"
android:text="Add Text"
android:visibility="gone"
android:padding="20dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/addPic"
android:text="Add Pic"
android:visibility="gone"
android:layout_gravity="center|bottom"
android:padding="20dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
android:id="@+id/delete"
android:visibility="gone"
android:layout_gravity="left|bottom"
android:padding="20dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:id="@+id/save_photo"
android:visibility="gone"
android:layout_gravity="right|top"
android:padding="20dp"/>
The EditText is a user interface which is used for entering and changing the text. While using edit text in XML layout, we must specify its inputType attribute which configures the keyboard according to input type mention.
add this in your EditText
xml,
android:imeOptions="flagNoExtractUi"
I'm not sure this method is not fit your needs, I hope you can help:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With