我遇到了問題,我的佈局是ImageView
。隨着AsyncTask
我從網上加載圖像。這是一張全景照片。如果我啓動Fragment
,我將加載src="@drawable/pano"
的圖像完美顯示。它有全高,我可以滾動瀏覽全景。更改圖像時更改ImageView大小
一旦新的圖像加載到ImageView
的ImageView的重定比例,這樣的高度:
之前的AsyncTask(圖像從繪圖資源加載中...):
這是後裝的AsyncTask形象:
這裏是我的xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:overScrollMode="never"
android:scrollbars="none" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/pano" />
</RelativeLayout>
</HorizontalScrollView>
的AsyncTask代碼:
public class DownloadPanorama extends
AsyncTask<ImageView, Void, Bitmap> {
ImageView imageView;
Bitmap bm;
public DownloadPanorama(ImageView mChart) {
imageView = mChart;
}
@Override
protected Bitmap doInBackground(ImageView... imageViews) {
return download_Image((String) imageView.getTag());
}
@Override
protected void onPostExecute(Bitmap result) {
imageView.setImageBitmap(result);
}
private Bitmap download_Image(String url) {
Bitmap bm = null;
try {
URL aURL = new URL(url);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
return bm;
}
}
不使用的AsyncTask,只使用原始setImageBitmap時也發生了......所以我不知道如果我要改變scaleType
在我的XML文件,或者如果我需要在加載新圖像後再次設置它?
嘗試改變的ImageView'安卓layout_height'到'match_parent' – iTurki
感謝您的幫助。這不起作用:( – user754730
你可以發佈你的'AsyncTask'代碼嗎? – Phil