问题描述
我在 ImageView 顶部有一个带有 Edittext 字段的视图.当键盘出现时,我希望窗口调整大小,以便 EditText 不再被键盘隐藏.在 AndroidManifest 文件中,我声明了 android:windowSoftInputMode="adjustResize" 并调整了屏幕大小,但问题是我希望不调整 ImageView 的大小.如何使 ImageView 不受影响?
I have a view with a Edittext field on top of an ImageView. When the keyboard comes up I want the window to resize so that EditText is no longer hidden by the keyboard. In the AndroidManifest file I declared android:windowSoftInputMode="adjustResize" and the screen is resized but the issue is that I want the ImageView to not be re-sized.
How can I make the ImageView unaffected?
我可以只用 ImageView 来扩展一个额外的布局,还是调整大小仍然会影响它?
Could I inflate an additional layout with just the ImageView or will the resize still affect it?
推荐答案
完整的解决方案涉及几个关键点
The full solution involves a few key points
- 使用
RelativeLayout,这样Views可以设置成相互重叠 - 使用
android:layout_alignParentBottom="true" 将 - 在您的清单中使用
android:windowSoftInputMode="adjustResize",以便在键盘弹出时Window的底部会发生变化(如您所述) - 把
ImageView放在一个ScrollView里面,这样ImageView就可以比Window大,然后禁用使用ScrollView#setEnabled(false) 在
EditText 与 Windows 的底部对齐ScrollView 上滚动- Use
RelativeLayout, so thatViewscan be setup to overlap one another - Align the
EditTextwith the bottom of theWindowsusingandroid:layout_alignParentBottom="true" - Use
android:windowSoftInputMode="adjustResize"in your manifest, so that the bottom of theWindowchanges when the keyboard pops up (as you mentioned) - Put the
ImageViewinside aScrollViewso that theImageViewcan be larger than theWindow, and disable scrolling on theScrollViewby usingScrollView#setEnabled(false)
这是布局文件
<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"
tools:context="com.so3.MainActivity">
<ScrollView
android:id="@+id/scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/stickfigures"/>
</ScrollView>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@android:color/holo_blue_bright"
android:text="Please enter text"
android:textSize="40sp"
android:gravity="center_horizontal"/>
</RelativeLayout>
这是我的活动
package com.so3;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ScrollView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ScrollView sv = (ScrollView)findViewById(R.id.scroll);
sv.setEnabled(false);
}
}
我的安卓清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.so3" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.so3.MainActivity"
android:windowSoftInputMode="adjustResize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我的解决方案的屏幕截图
Screen shots of my solution
这篇关于Android:使用屏幕上的软键盘仅调整部分视图的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)