pdf*_*dfj 51 android android-edittext window-soft-input-mode
我有一个在ImageView上面有一个Edittext字段的视图.当键盘出现时,我希望窗口调整大小,以便键盘不再隐藏EditText.在我宣布的AndroidManifest文件中android:windowSoftInputMode="adjustResize"
,屏幕调整大小,但问题是我希望ImageView不能重新调整大小.如何使ImageView不受影响?
我可以仅使用ImageView来扩充其他布局,还是调整大小仍会影响它?
Bri*_*ell 87
完整的解决方案涉及几个关键点
RelativeLayout
,以便Views
可以设置为彼此重叠EditText
与底部Windows
使用android:layout_alignParentBottom="true"
android:windowSoftInputMode="adjustResize"
在清单中使用,以便Window
在键盘弹出时更改底部(如您所述)ImageView
内部的ScrollView
,使得ImageView
可以比大Window
,并禁用滚动ScrollView
通过使用ScrollView#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>
Run Code Online (Sandbox Code Playgroud)
这是我的活动
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我的AndroidManifest
<?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>
Run Code Online (Sandbox Code Playgroud)
我的解决方案的屏幕截图
归档时间: |
|
查看次数: |
66410 次 |
最近记录: |