android - ScrollView 套 ImageView 显示异常

查看:93
本文介绍了android - ScrollView 套 ImageView 显示异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/img_background"
            android:scaleType="fitXY"/>

    </ScrollView>
    
</CoordinatorLayout>   

为了解决键盘弹出时背景图不被压缩才这样布局,可是里面的 ImageView中显示的图片却没有按照规定的大小显示,而是按照图片本身的尺寸显示,导致了在不同分辨率下图片显示不同(即便高度写死如200dp 还是按照图片本身的尺寸显示),所以在Nexus6p这种高分辨率的机型上底部会有未被 ImageView 覆盖到的区域,显示为白色。求解~

解决方案

当ScrollView没有fillViewport=true时,里面的元素(比如LinearLayout)会按照wrap_content来计算(不论它是否设了"match_parent")

这篇关于android - ScrollView 套 ImageView 显示异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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