【问题标题】:Stretching ImageView to fill screen height inside of Horizontal Scroll View拉伸 ImageView 以填充水平滚动视图内的屏幕高度
【发布时间】:2013-10-24 19:15:05
【问题描述】:

我已经阅读了有关支持不同屏幕密度的所有内容。而且,我已将正在显示的图像的适当变体提供给适当的文件夹。然而,我对某事感到困惑。 ImageView 的文档说将 android:layout_width 和 android:layout_height 设置为 "fill_parent"/"match_parent" 将导致图像拉伸以填充屏幕。 (这似乎是必要的,因为并非所有屏幕密度都提供相同尺寸/像素数的屏幕,我不希望那些额外的几个像素导致屏幕底部的填充) 这似乎在其他任何时候都有效,但是当 ImageView 放置在 Horizo​​ntalscrollview 内部并且图像的宽度比屏幕的宽度长时,这对我不起作用。

我的代码如下: (活动在我的清单中设置为横向)

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/hscrollview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp"
    android:fadingEdge="none"
    android:scrollbars="none"
    android:overScrollMode="never" >

<RelativeLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp"
    android:fadingEdge="none"
    android:scrollbars="none"
    android:overScrollMode="never" >

<ImageView
    android:id="@+id/MapImageView"
    android:src="@drawable/map"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent" />
</RelativeLayout>
</HorizontalScrollView>

编辑:我将 :src 替换为 :background 无效。

这是我在平板电脑等设备上获得的效果。理想情况下,我希望图像填满整个屏幕,就像它在下面一样,在具有典型 480x800 分辨率等的手机上。

【问题讨论】:

  • 请把你用上面的数据得到的图片和你想要的图片贴出来。并在ImageView中使用“background”而不是“src”
  • 已添加编辑。将 :src 更改为 :background 没有效果。
  • 最好将尺寸设置为“dp”作为高度吗?
  • 不要对高度或宽度使用硬编码值。这是一个不好的做法

标签: android imageview horizontalscrollview stretching


【解决方案1】:

尝试在您的ImageView中使用android:scaleType="fitXY"

【讨论】:

  • 当我将 :background 改回 :src o.O 时,您对仅设置的原始答案 :scaleType="fitXY" 工作正常
  • scaleTypes 仅适用于 src 引用
【解决方案2】:

这对我有用:

<ImageView
    android:id="@+id/main_imageView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="42dp"
    android:alpha="0.5"
    android:src="@drawable/img_alchemy2" />

它是一个纵向图像,在纵向模式下填充屏幕,在横向模式下它垂直填充而不水平拉伸。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2014-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多