Android:仅在屏幕上使用软键盘调整部分视图

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)

我的解决方案的屏幕截图

截图1 截图2

  • 但是如果情况是 width='match_parent" 并且图像很小,这种方式 imageview 不会全屏并且为了使其全屏,添加滚动视图 fillViewport 再次使软键盘上的图像调整大小弹出,请帮助。 (3认同)
  • 使它成为滚动视图并禁用滚动是我缺少的部分。我明天会尝试实施它。 (2认同)