1、首先加入smart image view 控件,通常直接粘貼源碼比較好 java
項目地址:http://loopj.com/android-smart-image-view/ android
佈局: app
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/widget32" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.loopj.android.image.SmartImageView android:id="@+id/siv" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1000" /> <EditText android:id="@+id/et" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:hint="請輸入地址" android:text="http://i7.hexunimg.cn/2013-03-29/152620496.jpg" android:textSize="18sp" /> <Button android:id="@+id/btn" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="click" android:text="獲取並瀏覽" /> </LinearLayout>
2、主activity ide
package com.pas.imageviewpro; import com.loopj.android.image.SmartImageView; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.EditText; public class MainActivity extends Activity { private EditText et_path; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et_path=(EditText)findViewById(R.id.et); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void click(View view) { SmartImageView siv=(SmartImageView)findViewById(R.id.siv); String url=et_path.getText().toString().trim(); siv.setImageUrl(url,R.drawable.ic_launcher,R.drawable.ic_launcher); } }