ImageView的大小调整时,键盘开启 [英] ImageView resizes when keyboard open

查看:253
本文介绍了ImageView的大小调整时,键盘开启的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent" >

<ImageView
    android:id="@+id/bgImage"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:contentDescription="@string/todo"
    android:scaleType="fitXY"
    android:src="@drawable/default_wallpaper" />

<LinearLayout
    android:id="@+id/mainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/title"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/in"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        android:cacheColorHint="@android:color/transparent"
        android:divider="@android:color/transparent"
        android:stackFromBottom="true"
        android:transcriptMode="alwaysScroll" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/edit_text_out"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_gravity="bottom"
            android:layout_weight="1"
            android:inputType="none" />

        <Button
            android:id="@+id/button_send"
            android:layout_width="70dp"
            android:layout_height="fill_parent"
            android:text="@string/send"
            android:textSize="15sp"
            android:textStyle="bold" />
    </LinearLayout>
</LinearLayout>

</RelativeLayout>

在此,当我在的EditText 点击软键盘打开,但我的的ImageView 正在萎缩。

In this when I tap on EditText soft keyboard opens but my ImageView is shrinking.

我用的android:windowSoftInputMode =adjustPan清单文件,但通过这一点,会推高整个活动上的一面,但我想ImageView的,因为它是当键盘是开放的ImageView从底部切断不是从顶部,在的WhatsApp 应用程序。

I used android:windowSoftInputMode="adjustPan" in manifest file but by using this it will push up whole activity upper side but I want ImageView as it is and when keyboard is open ImageView is cut from bottom not from top as in WhatsApp application.

任何帮助将AP preciate。谢谢。

Any help will appreciate. Thank you ..

推荐答案

我有一个类似的问题:在自定义视图 - ParallaxBackground - 我已经适应应该作为背景图像与由一 ViewPager 滚动在同一活动驱动的视差效应。

I had a similar issue in which a custom View - ParallaxBackground - that I've adapted was supposed to act as a background image with a parallax effect driven by the scroll of a ViewPager in the same activity.

在换句话说,我有比屏幕的稍大的宽度和显示图像视图时沿用户滚动 ViewPager ,在图像 ParallaxBackground 滚动一点为好。

In other words, I have a View that displays an image with a width slightly larger than the screen's and when the user scrolls along the ViewPager, the image in the ParallaxBackground scrolls a little as well.

现在在我的情况,我有一些EditTexts我ViewPager的片段内,当用户点击它们,导致软键盘显示的ParallaxBackground(因此,背景图像)将被重新调整大小和挤压的违背我的意愿。

Now in my case, I had some EditTexts inside my ViewPager's Fragments and when the user clicked on them, causing the soft keyboard to show up, the ParallaxBackground (and consequently, the background image) would be re-sized and squeezed "against my will".

所以我增加了一个布尔的IsBackground ,两个 INT S代表固定宽度 fixedHeight固定高度键,不顾我的视图的 onMeasure()像这样:

So I added a boolean isBackground, two ints for fixedWidth and fixedHeight and overrode my View's onMeasure() like so:

 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {


    if(isBackground) 
    // If this is being used as a background and is supposed to occupy the whole screen...
    {
                    // force the View to have the specified dimensions
        setMeasuredDimension(fixedWidth, fixedHeight);
    }
    // ...aply default measures...
    else
    {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

 }

我知道这是不是一个美丽的解决方案,但是,即使我的答案是不相关的问题100%,你可能想尝试延长的ImageView 类并覆盖 onMeasure

然后,在你的的onCreate 方法,你可以设置的IsBackground 为true,并给予固定宽度 fixedHeight固定高度为您测量屏幕宽度和高度的值。

Then, in your onCreate method you can set isBackground to true and give fixedWidth and fixedHeight the values for your measured screen width and height.

这篇关于ImageView的大小调整时,键盘开启的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆