【问题标题】:ImageView image is not appearing on large screen mobilesImageView 图像未出现在大屏幕手机上
【发布时间】:2013-10-01 18:02:51
【问题描述】:

我的图像高度约为 2000dp。我想在 ImageView 中显示它,它可以滚动到它的高度。我写了以下 xml 文件,它在设备上运行良好,但在 HTC one X、三星 Galaxy S4 等设备上运行良好,我认为这是大屏幕移动设备的问题,谁能帮帮我。我会非常感谢他/她。

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="2000dp"
    android:layout_below="@+id/total"
    android:scrollbars="vertical" >

    <FrameLayout
        android:id="@+id/relativeLayout"
        android:layout_width="fill_parent"
        android:layout_height="2000dp" >

        <RelativeLayout
            android:id="@+id/upperRelativeLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </RelativeLayout>

        <ImageView
            android:id="@+id/image1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="fitXY"
            android:src="@drawable/dayview_bg" />

        <ImageView
            android:id="@+id/image2"
            android:layout_width="fill_parent"
            android:layout_height="2dp"
            android:background="@android:color/white"
            android:scaleType="fitXY" />
    </FrameLayout>
</ScrollView>

【问题讨论】:

    标签: android imageview scrollview


    【解决方案1】:

    您应该尝试downsize your image 1) 匹配设备屏幕尺寸和 2) 避免内存问题,2000dp 高于现有标准设备的常规尺寸。

    您可以按照documentation 来根据目标设备定义不同的布局:

    • res/layout/my_layout.xml // 正常屏幕尺寸的布局(“默认”)
    • res/layout-small/my_layout.xml // 小屏幕布局
    • res/layout-large/my_layout.xml // 大屏幕布局
    • res/layout-xlarge/my_layout.xml // 超大屏幕布局
    • res/layout-xlarge-land/my_layout.xml // 横向超大布局

    配置示例

    为了帮助您针对不同类型的设备定位您的一些设计,以下是一些典型屏幕宽度的数字:

    • 320dp:典型的手机屏幕(240x320 ldpi、320x480 mdpi、480x800 hdpi 等)。
    • 480dp:类似于 Streak (480x800 mdpi) 的补间平板电脑。
    • 600dp:7 英寸平板电脑 (600x1024 mdpi)。
    • 720dp:10 英寸平板电脑(720x1280 mdpi、800x1280 mdpi 等)。

    如果您不想缩小整个图像,BitmapRegionDecoder class 可以帮助您(使用案例可以在this post 中找到)

    【讨论】:

    • 我有一个大图像,这就是为什么我使用滚动视图来上下滚动它,为什么你说要支持多个屏幕,这不是我要问的。
    • 由于大多数设备的内存有限,您的图像无法保留在内存中(内存不足问题);您可以尝试缩小它,在布局中显示它的一部分,使用具有内置缩放功能的 web 视图(在 HTML 页面中使用 加载图像)
    • BitmapRegionDecoder class可以帮到你(使用案例见this post
    猜你喜欢
    • 2020-12-11
    • 2018-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 2020-05-03
    相关资源
    最近更新 更多