問(wèn)題描述
我在 ImageView 頂部有一個(gè)帶有 Edittext 字段的視圖.當(dāng)鍵盤(pán)出現(xiàn)時(shí),我希望窗口調(diào)整大小,以便 EditText 不再被鍵盤(pán)隱藏.在 AndroidManifest 文件中,我聲明了 android:windowSoftInputMode="adjustResize"
并調(diào)整了屏幕大小,但問(wèn)題是我希望不調(diào)整 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 來(lái)擴(kuò)展一個(gè)額外的布局,還是調(diào)整大小仍然會(huì)影響它?
Could I inflate an additional layout with just the ImageView or will the resize still affect it?
推薦答案
完整的解決方案涉及幾個(gè)關(guān)鍵點(diǎn)
The full solution involves a few key points
- 使用
RelativeLayout
,這樣Views
可以設(shè)置成相互重疊 - 使用
android:layout_alignParentBottom="true"
將 - 在您的清單中使用
android:windowSoftInputMode="adjustResize"
,以便在鍵盤(pán)彈出時(shí)Window
的底部會(huì)發(fā)生變化(如您所述) - 把
ImageView
放在一個(gè)ScrollView
里面,這樣ImageView
就可以比Window
大,然后禁用使用ScrollView#setEnabled(false)
在
EditText
與 Windows
的底部對(duì)齊ScrollView
上滾動(dòng)- Use
RelativeLayout
, so thatViews
can be setup to overlap one another - Align the
EditText
with the bottom of theWindows
usingandroid:layout_alignParentBottom="true"
- Use
android:windowSoftInputMode="adjustResize"
in your manifest, so that the bottom of theWindow
changes when the keyboard pops up (as you mentioned) - Put the
ImageView
inside aScrollView
so that theImageView
can be larger than theWindow
, and disable scrolling on theScrollView
by 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>
這是我的活動(dòng)
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
這篇關(guān)于Android:使用屏幕上的軟鍵盤(pán)僅調(diào)整部分視圖的大小的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!