您好我是Android的新手,我试图缩放图像,如果点击..问题是我想要缩放的图像来自数据库... 这是我的xml代码..
`<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_weight="50"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="@+id/labresultimage"
android:layout_width="460dp"
android:layout_height="320dp"
android:src="@drawable/laboratory" />
</LinearLayout>`
这是我的java代码..
`package info.androidhive.slidingmenu;
import java.io.InputStream;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
public class LaboratoryResultInformation extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.laboratoryresultinformation);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
//display image using passed url
final String MY_URL_STRING = extras.getString("IMAGEURL_EXTRA");
new DownloadImageTask((ImageView) findViewById(R.id.labresultimage))
.execute(MY_URL_STRING);
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
}`
我用谷歌搜索,但我找到的唯一代码如果图像本身已经定位/保存在drawables上有效..
答案 0 :(得分:0)
下载图像位图后 您可以尝试,https://github.com/MikeOrtiz/TouchImageView/tree/master/src/com/example/touch或https://github.com/jasonpolites/gesture-imageview 保持图像视图
android:layout_width="wrap_content"
android:layout_height="wrap_content"
无论您是获得位图对象表单服务器还是区域设置都无关紧要。