简单粗暴点。。直接上代码。
导入的包:
<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