天天看點

android ImageLoader圖檔加載

簡單粗暴點。。直接上代碼。

導入的包:

<span style="font-size:18px;">import io.guaju.imageloadertest.app.MyApp;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ImageView;


</span>
           
<span style="font-size:18px;">MainActivity.java中的代碼:
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        MyApp.getImageLoader(getApplicationContext()).
        displayImage("http://y2.ifengimg.com/a/2015_38/2cafb01b79a4f86.jpg",
        		(ImageView)findViewById(R.id.iv1),
        		MyApp.options1);
        MyApp.getImageLoader(getApplicationContext()).
        displayImage("http://y2.ifengimg.com/a/2015_38/2cafb01b79a4f86.jpg",
        		(ImageView)findViewById(R.id.iv2),
        		MyApp.options2);
    }


    @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;
    }
    
}

</span>
           

XML中的代碼:

</pre><pre name="code" class="html"><span style="font-size:18px;">    <ImageView
    	android:id="@+id/iv1"
        android:layout_width="400dp"
        android:layout_height="300dp"
       />
    <ImageView
        android:layout_marginTop="20dp"
    	android:id="@+id/iv2"
        android:layout_width="400dp"
        android:layout_height="300dip"
       /></span>
           

注意:在布局檔案中設定ImageView的寬高必須自己定義,不能設定match_parent或者wrap_content。

結束。over

繼續閱讀