Android ScrollView 中放入 ImageView 导致的出现上下白边的问题?


这是在一个项目中遇到的一个问题,一直弄不明白在平板上显示正常,但是在手机上会出现上下白边,过了好大一会儿才找到解决办法。

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <include
        android:id="@+id/***"
        layout="@layout/***" />
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
            <ImageView
                android:id="@+id/iv_guide_detail"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal" />
    </ScrollView>
</LinearLayout>

这样在手机上面会出现ImageView上下都有一块空白,解决问题的做法就是在ImageView 中添加下面的一段代码:

 scaleType=“fillXY”
这样也有弊端,图片会出现轻微缩放,导致失真。

下面一种方式也能解决这个问题

ref:http://wang-peng1.iteye.com/blog/675974




原文地址:https://www.cnblogs.com/jinfenglee/p/4388701.html