0

所以我试图将图像放在滚动视图中并让图像拉伸以适应不同尺寸的屏幕。它会水平伸展,但垂直方向总是乱七八糟。

我读过很多有类似问题的人的页面,但他们的解决方案对我不起作用。我已经尝试了使用不同scaleType的 ,layout_width和的所有不同组合,并layout_height尝试改变其他东西。下面的代码显示了我最接近让它工作的方法,使用scaleType="centerCrop". 它是唯一一个按比例垂直拉伸图像的功能,但它会从顶部和底部切掉一大块图像,它会上下滚动图像,但只显示中间部分。

该图像是 480x5500 jpeg,如果这很重要的话。最初在我开始搞砸这一切之前,该应用程序在我的手机上运行良好,但后来我意识到当我在平板电脑上尝试时图像被压缩了。必须有一种方法可以在 xml 中执行此操作,对吗?我真的不想对 java 代码部分中的图像做任何事情。另外我希望能够只使用一张图片来做到这一点,我不想为不同的屏幕尺寸使用不同的图片。请帮忙,谢谢。

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:src="@drawable/paper" />
</ScrollView>    
4

3 回答 3

0

可能这对你有帮助,使高度和wrap_content宽度ImageView

  android:layout_width="wrap_content"
  android:layout_height="wrap_content"

这里不需要ScrollView

于 2013-02-16T05:13:32.353 回答
0

下一个样本超出了您的要求:

hotview.sample

它使图像适合屏幕,此外还允许使用捏合手势放大/缩小。

于 2013-02-16T21:31:21.147 回答
0

尝试使用此处提到的 AspectRatioImageView 之类的自定义 ImageView:

https://stackoverflow.com/a/4688335/944070

于 2013-02-16T20:56:22.513 回答