我想在每个
旁边的网址中显示多个图片视图我的xml是:
<HorizontalScrollView android:id="@+id/horizontalScroll"
android:visibility="gone"
android:layout_width="wrap_content"
android:background="#EEEEEE"
android:layout_height="100dp"
android:scrollbars="horizontal"
android:layout_gravity="center">
<LinearLayout
android:id="@+id/imgLayout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="wrap_content">
</LinearLayout>
</HorizontalScrollView>
我的java代码:
Drawable imgg;
ImageView image;
LinearLayout layout;
layout = (LinearLayout)findViewById(R.id.imgLayout);
private void grabImageFromUrl(String url) throws Exception
{
imgg = Drawable.createFromStream((InputStream)new URL(url).getContent(), "src");
}
/////////////////////////////////////////////////////////////////////////////////////////
class DownloadImageFromURL extends AsyncTask<String, String, String> {
String _ads;
public DownloadImageFromURL(String ads)
{
_ads = ads;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... f_url) {
image = new ImageView(getApplicationContext());
image.setId(imgId++);
try
{
grabImageFromUrl("http://dariran.com/Ads/Mobile/Small/" + _ads);
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
protected void onProgressUpdate(String... progress) {
}
@Override
protected void onPostExecute(String file_url) {
try
{
image.setImageDrawable(imgg);
layout.addView(image);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
DownloadImageFromURL Class
建立在循环语法(图像计数)
我加载了图像,但它们相互叠加 我不知道为什么不能显示真实。