[英]EditText Is Not Visible With Open Keyboard
I have a fullscreen activity with a fullscreen ImageView in the background. 我在后台使用全屏ImageView进行全屏活动。 I have an EditText placed in the middle of the screen using
gravity:center
. 我使用
gravity:center
将一个EditText放在屏幕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. 当键盘打开时,我想让EditText向上移动,如下图所示,这样整个EditText始终可见。 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. 我曾尝试使用
android:windowSoftInputMode="stateVisible|adjustResize"
但问题是我的背景图像也调整了大小,这是不可取的。 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. 此外,由于重力设置为中心,因此EditText与键盘之间存在间隙,因此它仍处于中心位置。 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.
我尝试过使用scrollView但是我不知道如何获得键盘结束的位置,以便我可以将EditText移动到该位置。 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. 我也尝试过
adjustPan
但是这没有任何效果,因为EditText的高度为200dp
,重力设置为居中,所以用户总是在仍然可见的EditText中间开始输入。
XML 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"/>
add this in your EditText
xml, 在
EditText
xml中添加它,
android:imeOptions="flagNoExtractUi"
I'm not sure this method is not fit your needs, I hope you can help:) 我不确定这种方法不适合你的需求,希望你能帮忙:)
Open up your menifest.xml find your activity and add this single line 打开你的menifest.xml找到你的活动并添加这一行
<activity android:windowSoftInputMode="adjustResize" />
or 要么
<activity android:windowSoftInputMode="adjustPan" />
your activity tag should look like below 您的活动代码应如下所示
<activity
android:name="com.my.MainActivity" //Change this to your.package.ActivityName
android:screenOrientation="portrait"
android:label="@string/title_activity_main"
android:windowSoftInputMode="adjustPan" >
</activity>
or 要么
<activity
android:name="com.my.MainActivity" //Change this to your.package.ActivityName
android:screenOrientation="portrait"
android:label="@string/title_activity_main"
android:windowSoftInputMode="adjustResize" >
</activity>
Update 1 更新1
<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:id="@+id/picturedisplay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<LinearLayout
android:id="@+id/pic_layout"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_gravity="center"
android:background="#9945D199"
android:gravity="center"
android:orientation="vertical"
android:visibility="visible">
<EditText
android:id="@+id/pic_textbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom|center"
android:hint="Enter text here..."
android:maxLength="250"
android:maxLines="6"
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/char_rem_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="200"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
<Button
android:id="@+id/imgClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:padding="20dp"
android:text="Flip Cam" />
<Button
android:id="@+id/snap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:padding="20dp"
android:text="Capture" />
<Button
android:id="@+id/imgOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:padding="20dp"
android:text="Flash"
android:visibility="visible" />
<Button
android:id="@+id/addText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:padding="20dp"
android:text="Add Text"
android:visibility="gone" />
<Button
android:id="@+id/addPic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:padding="20dp"
android:text="Add Pic"
android:visibility="gone" />
<Button
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:padding="20dp"
android:text="Delete"
android:visibility="gone" />
<Button
android:id="@+id/save_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|top"
android:padding="20dp"
android:text="Save"
android:visibility="gone" />
</FrameLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.