我使用Html.fromHtml()
来获取内容并将其显示在我的活动中。为此,我正在使用ImageGetter。我有一个问题,如果手机无法连接到互联网的应用程序崩溃,因为图片无法加载。相反,我想要一个占位符图像保存在我的ldpi/mdpi/...etc
文件夹中,只要无法加载图片就会插入。ScrollView无法与Drawables一起使用Android
我ImageGetter使用URLImageParser它具有以下onPostExecute()方法:
@Override
protected void onPostExecute(Drawable result) {
//check to see if an image was found (if not could
//be due to no internet)
if(result ==null){
//the drawable wasn't found so use the image not found
//png
Drawable imageNotFound = a.getResources().getDrawable(R.drawable.image_not_found);
result = imageNotFound;
}
intrinsicHeight = result.getIntrinsicHeight();
intrinsicWidth = result.getIntrinsicWidth();
DisplayMetrics dm = new DisplayMetrics();
((WindowManager) c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels -50;
int height = width * intrinsicHeight/intrinsicWidth;
result.setBounds(0, 0, 0 + width, 0
+ height);
urlDrawable.setBounds(0, 0, 0+width, 0+height);
// change the reference of the current drawable to the result
// from the HTTP call
urlDrawable.drawable = result;
// redraw the image by invalidating the container
URLImageParser.this.container.invalidate();
// For ICS
URLImageParser.this.container.setHeight((URLImageParser.this.container.getHeight()
+ height));
// Pre ICS
URLImageParser.this.container.setEllipsize(null);
}
我已经在这个方法的顶部简单地插入的,如果(result==null)
声明。但现在,如果图片可以加载的应用程序完美的作品。如果图片无法加载,而占位符被使用,我会得到一些奇怪的行为。
scrollview从不滚动到屏幕的底部,我不知道这是为什么。理论上,我的imageNotFound可绘制(这是一个PNG文件)和从互联网上下载的文件应该没有区别。滚动视图只会稍微移动。
我不知道这是什么原因造成的。在网上搜索时,大多数人似乎在使用RelativeLayouts时遇到问题。我找不到任何人使用drawable或TableLayouts遇到问题。
我的布局XML如下:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingBottom = "0dip"
android:orientation = "vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1"
android:shrinkColumns="0,1"
android:id = "@+id/SharedTableLayout"
android:paddingBottom = "0dip" >
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingBottom = "0dip">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id = "@+id/SharedTableContent"
android:layout_span="2"
android:gravity = "left"
android:paddingLeft = "10dip"
android:paddingRight = "10dip"
android:paddingTop = "20dip"
android:paddingBottom = "0dip"/>
</TableRow>
</TableLayout>
</ScrollView>
我真的很感激有这方面的建议,我已经遇到好几周了。
感谢您的时间
ID为SharedTableContent TextView的显示从HTML使用Html.fromHtml()转换的字符串,因此图像可以通过文本,这意味着我不能硬编码的溶液成XML作为包围没有办法告诉将要提前下载多少图像,这些都是以编程方式完成的。
相反ScrollView'的'为什么不ü尝试用['名单View'] (http://developer.android.com/guide/topics/ui/layout/listview.html)任何特定的原因和加载图像使用['volley'](http://developer.android.com/training/volley /request.html)或['picasso'](http://square.github.io/picasso/) – kId
我对android比较陌生,我从来没有听说过ListView。会自动滚动吗? – user3707803
当然,它会滚动'垂直' – kId