简体   繁体   English

Android如何在键盘弹出时忽略自动调整大小?

[英]Android how to ignore auto resizing when keyboard pops up?

let's say I have a view that is made up of 2 layers -> top layer and bottom layer. 假设我有一个由2层组成的视图->顶层和底层。 I place them both in a frame layout. 我把它们都放在框架布局中。

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- bottom layer -->
    <ImageView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/some_image_you_shouldnt_shrink"/>

    <!-- top layer -->
    <EditText 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/somewhat_transparent"/>

</FrameLayout>

now, presumably, when i tap on the editText, the keyboard will pop up, and shrink the size of the edit text. 现在,大概是当我点击editText时,键盘会弹出,并缩小编辑文本的大小。 However, it seems that the bottom layer is ALSO getting resized. 但是,似乎底层也正在调整大小。 How do i prevent this bottom layer from getting resized? 我如何防止调整底层大小?

Note: the framelayout is in a fragment, and the activity that holds this fragment must declare android:windowSoftInputMode="adjustResize" . 注意:framelayout在一个片段中,并且保存该片段的活动必须声明android:windowSoftInputMode="adjustResize"

EDIT* * ** * ** * * 编辑* * ** * ** * *

Just to clarify, i want the editText layer to adjust as high as the keyboard needs to. 只是为了澄清一下,我希望editText层可以根据键盘的需要进行调整。 however, i don't want the image behind it to adjust at all 但是,我根本不想调整它后面的图像

i only have 1 activity that handles these similar types of fragments. 我只有1个活动来处理这些相似类型的片段。

You can't prevent a single view from resizing if you set android:windowSoftInputMode="adjustResize" . 如果您设置了android:windowSoftInputMode="adjustResize"则无法阻止调整单个视图的大小。 But if you just want to set a non-resizing background, there is a work-around. 但是,如果您只想设置不调整大小的背景,则有一种变通方法。 Instead of setting the background image in the ImageView through XML, add this in your onCreate() method 与其通过XML在ImageView中设置背景图片,不如在您的onCreate()方法中添加背景图片

getWindow().setBackgroundDrawableResource(R.drawable.some_image_you_shouldnt_shrink);

尝试在清单中

android:windowSoftInputMode="stateVisible|adjustPan"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM