测试出了说 图片变形了, 原因是因为我 把 高度设置成了 wrap_content 宽度 设置成了 match_parent scaleType 设置成了fitXY 这一次 对ImageView 不做任何限制 全部是 wrap_content
public class MainActivity extends Activity {
private ImageView main_iv;
private String urlPath="http://xxxxxxxx/xxxx/jpg/test/2017/01/10/352ae8442ac042649e8a407e86725b91.jpg";
Handler handler = new Handler(){
public void handleMessage(android.os.Message msg) {
if(msg.obj!=null){
Bitmap bitmap = (Bitmap) msg.obj;
main_iv.setImageBitmap(bitmap);
}
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
main_iv = (ImageView) findViewById(R.id.main_iv);
}
public void getPic(View v){
new Thread(new Runnable() {
@Override
public void run() {
try {
URL url = new URL(urlPath);
try {
URLConnection connection = url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(stream);
Message msg = Message.obtain();
msg.obj=bitmap;
handler.sendMessage(msg );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
}