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

时间:2014-03-21 04:13:31

标签: android android-layout android-fragments

假设我有一个由2层组成的视图 - >顶层和底层。我把它们放在一个框架布局中。

<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>

现在,据推测,当我点击editText时,键盘会弹出,缩小编辑文本的大小。但是,似乎底层也正在调整大小。如何防止底层调整大小?

注意:framelayout位于片段中,包含此片段的活动必须声明android:windowSoftInputMode="adjustResize"

编辑*的 * ** * ** * *

为了澄清,我希望editText图层可以调整到键盘所需的高度。但是,我不希望它背后的图像完全调整

我只有1个活动来处理这些类似的片段。

2 个答案:

答案 0 :(得分:1)

如果设置android:windowSoftInputMode="adjustResize",则无法阻止单个视图调整大小。但是如果你只是想设置一个非调整大小的背景,那就有一个解决方法。不是通过XML在ImageView中设置背景图像,而是在onCreate()方法

中添加
getWindow().setBackgroundDrawableResource(R.drawable.some_image_you_shouldnt_shrink);

答案 1 :(得分:0)

在清单中尝试这个

android:windowSoftInputMode="stateVisible|adjustPan"