標籤:android基礎
介面效果
應用的許可權
<uses-permission android:name="android.permission.INTERNET"/>
布局檔案
<LinearLayout 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:orientation="vertical" tools:context=".MainActivity" > <com.loopj.android.image.SmartImageView android:id="@+id/siv" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="100" /> <EditText android:id="@+id/et_path" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="請輸入圖片地址" android:singleLine="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="checkImage" android:text="@string/bt_catchImage" /></LinearLayout>
核心檔案
package com.examp.use_android_smart_image_view;import com.loopj.android.image.SmartImageView;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.EditText;public class MainActivity extends Activity {private EditText et_path;private SmartImageView siv;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);et_path = (EditText) findViewById(R.id.et_path);et_path.setText("http://c.hiphotos.baidu.com/image/w%3D310/sign=1ebfb751a6c27d1ea5263dc52bd4adaf/78310a55b319ebc47dc5736c8026cffc1f171681.jpg");}public void checkImage(View view) {siv = (SmartImageView) findViewById(R.id.siv);// 載入的路徑|如果沒有載入到顯示的內容|等待載入的圖片siv.setImageUrl(et_path.getText().toString().trim(),R.drawable.ic_launcher, R.drawable.ic_launcher);}}
注:使用前提,需要加入Android-smart-image-view架構
: