MainActivity.class
package com.example.xutils_com; import java.util.ArrayList; import java.util.List; import com.lidroid.xutils.BitmapUtils; import android.os.Bundle; import android.app.Activity; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.ListView; public class MainActivity extends Activity { private ListView list_view; private BitmapUtils bitmapUtils; private List<String> list=new ArrayList<String>(); private String[] img_url = new String[] { "http://xinshipu.cn/20110528/smallImage1/1306536264861.jpg", "http://xinshipu.cn/20100506/smallImage1/1273157301640.jpg", "http://xinshipu.cn/20110721/smallImage1/1311234728768.jpg", "http://xinshipu.cn/20100605/smallImage1/1275738758736.jpg", "http://xinshipu.cn/20100506/smallImage1/1273106865078.jpg", "http://xinshipu.cn/20100613/smallImage1/1276425889259.jpg", "http://xinshipu.cn/20100521/original/1274403878791.jpg", "http://xinshipu.cn/20110403/smallImage1/1301805300564.jpg", "http://xinshipu.cn/20100325/smallImage1/1269459830286.jpg", "http://xinshipu.cn/20150102/original/1420152641128.jpg", "http://xinshipu.cn/20100809/smallImage1/1281348073140.jpg", "http://xinshipu.cn/20140706/smallImage1/1404599235077.jpg", "http://xinshipu.cn/20100325/smallImage1/1269495282911.jpg", "http://xinshipu.cn/20130320/smallImage1/1363712079835.jpg", "http://xinshipu.cn/20100323/smallImage1/1269319132942.jpg", "http://xinshipu.cn/20100325/smallImage1/1269465144254.jpg", "http://xinshipu.cn/20110627/smallImage1/1309127322498.jpg", "http://xinshipu.cn/20150312/original/1426129355728.jpg" }; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); list_view=(ListView) findViewById(R.id.list_view); for(int i=0;i<img_url.length;i++){ list.add(img_url[i]); } list_view.setAdapter(base); } BaseAdapter base=new BaseAdapter() { @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub convertView=LayoutInflater.from(getApplicationContext()).inflate(R.layout.page,null); ImageView iamge_view=(ImageView) convertView.findViewById(R.id.iamge_view); bitmapUtils = new BitmapUtils(getApplicationContext()); bitmapUtils.display(iamge_view, list.get(position)); return convertView; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return list.get(position); } @Override public int getCount() { // TODO Auto-generated method stub return list.size(); } }; @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
activity.xml:里面就是一个简单的listview
page.xml里面就是一个简单的imageview
效果图: