SmartImageView
2016-05-26 21:21
169 查看
<RelativeLayout 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" >
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</RelativeLayout>
**********************************************************************
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.loopj.android.image.SmartImageView
android:id="@+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp" />
<TextView
android:id="@+id/textView_intro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView"
android:layout_marginBottom="27dp"
android:layout_toRightOf="@+id/imageView"
android:text="fffffffffffffffffffddddddddddddd" />
<TextView
android:id="@+id/textView_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView_intro"
android:layout_alignLeft="@+id/textView_intro"
android:layout_marginBottom="16dp"
android:text="fffffffffffffffffff" />
</RelativeLayout>
==================================================================================
package com.example.day_07_SmartImageView;
import java.io.IOException;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.example.day_07_SmartImageView.bean.Bean;
import com.example.day_07_SmartImageView.bean.NewsInfo;
import com.google.gson.Gson;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class MainActivity extends Activity {
String path = "http://api.sina.cn/sinago/list.json?channel=hdpic_story&adid=4ad30dabe134695c3d7c3a65977d7e72&from=6042095012&chwm=12050_0001&imei=867064013906290&uid=802909da86d9f5fc&p=1";
private List<NewsInfo> list;
Handler handler=new Handler(){
public void handleMessage(android.os.Message msg) {
Bean bean = (Bean) msg.obj;
list = bean.data.list;
MyAdapter myAdapter=new MyAdapter(MainActivity.this,list);
listView.setAdapter(myAdapter);
};
};
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listView);
//点击进入详情
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
list.get(position);
}
});
new Thread() {
public void run() {
sendGet();
};
}.start();
}
/**
* 请求网络
*/
protected void sendGet() {
HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(path);
try {
HttpResponse httpResponse = httpClient.execute(httpGet);
if(httpResponse.getStatusLine().getStatusCode()==200){
HttpEntity entity = httpResponse.getEntity();
String json = EntityUtils.toString(entity);
Gson gson=new Gson();
Bean bean = gson.fromJson(json, Bean.class);
Message msg=Message.obtain();
msg.obj=bean;
handler.sendMessage(msg);
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
=====================================================================================================
适配器
/**
*
*/
package com.example.day_07_SmartImageView;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.day_07_SmartImageView.bean.NewsInfo;
import com.loopj.android.image.SmartImageView;
/**
* @author WJL
*
*/
public class MyAdapter extends BaseAdapter {
Context context; List<NewsInfo> list;
/**
* @param mainActivity
* @param list
*/
public MyAdapter(Context context, List<NewsInfo> list) {
this.context=context;
this.list=list;
}
/* (non-Javadoc)
* @see android.widget.Adapter#getCount()
*/
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
/* (non-Javadoc)
* @see android.widget.Adapter#getItem(int)
*/
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see android.widget.Adapter#getItemId(int)
*/
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
/* (non-Javadoc)
* @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView=View.inflate(context,R.layout.item, null);
SmartImageViewimageView=
(SmartImageView) convertView.findViewById(R.id.imageView);
TextView
textView_intro= (TextView) convertView.findViewById(R.id.textView_intro);
TextView
textView_title= (TextView) convertView.findViewById(R.id.textView_title);
textView_intro.setText(list.get(position).intro);
textView_title.setText(list.get(position).title);
//使用SmartImageView展示网络图片,传入图片网络地址即可
imageView.setImageUrl(list.get(position).pic);
return convertView;
}
}
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</RelativeLayout>
**********************************************************************
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.loopj.android.image.SmartImageView
android:id="@+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp" />
<TextView
android:id="@+id/textView_intro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView"
android:layout_marginBottom="27dp"
android:layout_toRightOf="@+id/imageView"
android:text="fffffffffffffffffffddddddddddddd" />
<TextView
android:id="@+id/textView_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView_intro"
android:layout_alignLeft="@+id/textView_intro"
android:layout_marginBottom="16dp"
android:text="fffffffffffffffffff" />
</RelativeLayout>
==================================================================================
package com.example.day_07_SmartImageView;
import java.io.IOException;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import com.example.day_07_SmartImageView.bean.Bean;
import com.example.day_07_SmartImageView.bean.NewsInfo;
import com.google.gson.Gson;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class MainActivity extends Activity {
String path = "http://api.sina.cn/sinago/list.json?channel=hdpic_story&adid=4ad30dabe134695c3d7c3a65977d7e72&from=6042095012&chwm=12050_0001&imei=867064013906290&uid=802909da86d9f5fc&p=1";
private List<NewsInfo> list;
Handler handler=new Handler(){
public void handleMessage(android.os.Message msg) {
Bean bean = (Bean) msg.obj;
list = bean.data.list;
MyAdapter myAdapter=new MyAdapter(MainActivity.this,list);
listView.setAdapter(myAdapter);
};
};
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listView);
//点击进入详情
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
list.get(position);
}
});
new Thread() {
public void run() {
sendGet();
};
}.start();
}
/**
* 请求网络
*/
protected void sendGet() {
HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(path);
try {
HttpResponse httpResponse = httpClient.execute(httpGet);
if(httpResponse.getStatusLine().getStatusCode()==200){
HttpEntity entity = httpResponse.getEntity();
String json = EntityUtils.toString(entity);
Gson gson=new Gson();
Bean bean = gson.fromJson(json, Bean.class);
Message msg=Message.obtain();
msg.obj=bean;
handler.sendMessage(msg);
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
=====================================================================================================
适配器
/**
*
*/
package com.example.day_07_SmartImageView;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.day_07_SmartImageView.bean.NewsInfo;
import com.loopj.android.image.SmartImageView;
/**
* @author WJL
*
*/
public class MyAdapter extends BaseAdapter {
Context context; List<NewsInfo> list;
/**
* @param mainActivity
* @param list
*/
public MyAdapter(Context context, List<NewsInfo> list) {
this.context=context;
this.list=list;
}
/* (non-Javadoc)
* @see android.widget.Adapter#getCount()
*/
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
/* (non-Javadoc)
* @see android.widget.Adapter#getItem(int)
*/
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see android.widget.Adapter#getItemId(int)
*/
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
/* (non-Javadoc)
* @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView=View.inflate(context,R.layout.item, null);
SmartImageViewimageView=
(SmartImageView) convertView.findViewById(R.id.imageView);
TextView
textView_intro= (TextView) convertView.findViewById(R.id.textView_intro);
TextView
textView_title= (TextView) convertView.findViewById(R.id.textView_title);
textView_intro.setText(list.get(position).intro);
textView_title.setText(list.get(position).title);
//使用SmartImageView展示网络图片,传入图片网络地址即可
imageView.setImageUrl(list.get(position).pic);
return convertView;
}
}
相关文章推荐
- 先贤祠1
- LeetCode 31. Next Permutation
- Theano: CNMeM is disabled, CuDNN not available
- Javascript Lazyload图片延迟加载特效,降低HTPP连接次数,提高页面访问时间
- 海量数据处理常见面试题
- Hive 数据倾斜解决方案(调优)
- 《统计陷阱》读后感
- 嵌入式 Linux下编译并使用curl静态库
- maven创建项目命令
- 如何利用maven向本地仓库导入官网没有的jar包
- JDK 动态代理实现原理
- X64操作系统组件Jmail无法正常服务问题
- 学习进度12
- K近邻算法(二)程序
- 51nod 1006
- java static的作用详解(转)
- js近期心得体会
- 字符流FileWriter,FileReader、缓冲区,BufferReader,BufferWriter,IO的简单异常处理
- 查找算法之顺序查找
- HDOJ 5410 CRB and His Birthday