【问题标题】:Android: ImageSwitcher inside Scrollview places image at bottom of the screenAndroid:Scrollview 内的 ImageSwitcher 将图像置于屏幕底部
【发布时间】:2011-07-08 01:01:55
【问题描述】:

所以我创建了一个简单的小应用程序,它在 ImageSwitcher 中包含相当高的图像,并且由于图像的高度,我将 ImageSwitcher 包装在 ScrollView 中(因此整个图像最终可见)。有趣的是,图像不是从 ScrollView 的顶部开始,而是从底部开始。滚动一切正常,但我只是好奇为什么图像的顶部几乎在设备屏幕的底部。

有谁知道是什么导致了这种行为?

我的图像是大型可绘制对象 (800x600),显然为了适应设备窗口而被缩小了,但这仍然不能解释为什么图像上方有这么大的空白空间。

我宁愿只滚动 ImageSwitcher 本身,但到目前为止还没有工作。

这是我的布局:

<ScrollView android:id="@+id/scroll"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
     <ImageSwitcher android:id="@+id/switcher"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:background="#FFFFFF"/>
</ScrollView>

【问题讨论】:

    标签: android android-layout scrollview imageswitcher


    【解决方案1】:

    我的怀疑是由于原始图像的分辨率而显示图像。我设置了ImageView.setScaleType(ScaleType.FIT_START);,这似乎解决了问题。

    【讨论】:

    • 这解决了图像上方多余空间的问题,但是如果您在 ImageView 之后添加新控件,多余的空间现在位于图像下方......有什么想法吗?
    【解决方案2】:

    尝试在 setScaleType 之外调用 ImageView.setAdjustViewBounds(true)。如果您的 ImageView(在 ImageSwitcher 内部)占用的空间超过所需空间,仍然存在问题,请尝试使用 SDK 工具中的层次结构查看器查看 ImageView。

    【讨论】:

    • 在你的 xml 中使用 android:adjustViewBounds="true" 也可以
    猜你喜欢
    • 2015-03-17
    • 2013-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多