Android显示一张很长的图

当使用ScrollView嵌套ImageView加载大图无法显示时,可以尝试将大图切分为多个小图,或者关闭部分设备的硬件加速。此外,通过WebView加载图片也是一种可行方案,无论是加载互联网资源还是本地文件。

 scrollview嵌套一个imageview,显示一张很大的图片的时候,图片显示不出来,布局如下:

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/shouye1" />

</ScrollView>

解决方案:

(1):把那张很大的图片切成很多张小图片,然后

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/shouye1" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/shouye2" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/shouye3" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/shouye4" />
    </LinearLayout>
</ScrollView>
(2):取消硬件加速

<application
    android:hardwareAccelerated="false" >

有的设备取消硬件加速就可以显示了。


(3)可以放弃这种嵌套的方便,选择WebView来显示一张图片

<WebView
    android:id="@+id/blog_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

path为图片路径:

互联网用:webView.loadUrl("http:"+path);
本地文件用:webView.loadUrl("file:"+path);


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值