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);