首页| 新闻| 娱乐| 游戏| 科普| 文学| 编程| 系统| 数据库| 建站| 学院| 产品| 网管| 维修| 办公| 热点
本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下
XML布局
主页面main布局
<com.handmark.pulltorefresh.library.PullToRefreshListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/pull" ></com.handmark.pulltorefresh.library.PullToRefreshListView>
pulllist布局
<ImageView android:layout_width="120dp" android:layout_height="100dp" android:id="@+id/iv" /><TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tv" />
java代码
App页面
package com.example.duanpengpenglx20171108;import android.app.Application;import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;import com.nostra13.universalimageloader.core.DisplayImageOptions;import com.nostra13.universalimageloader.core.ImageLoader;import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;import com.nostra13.universalimageloader.core.assist.QueueProcessingType;import com.nostra13.universalimageloader.core.download.BaseImageDownloader;/** * Created by 朋 on 2017/11/8. */public class App extends Application { @Override public void onCreate() { super.onCreate(); ImageLoaderConfiguration config = new ImageLoaderConfiguration .Builder(this) .memoryCacheExtraOptions(480,800) .threadPoolSize(5) .threadPriority(Thread.NORM_PRIORITY - 2) .denyCacheImageMultipleSizesInMemory() .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation/你可以通过自己的内存缓存实现 .memoryCacheSize(2 * 1024 * 1024) .tasksProcessingOrder(QueueProcessingType.LIFO) .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) .imageDownloader(new BaseImageDownloader(this, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间 .writeDebugLogs() // Remove for release app .build();//开始构建//初始化imageloader; ImageLoader.getInstance().init(config); }}
MainActivity页面
public class MainActivity extends AppCompatActivity { List<Jbean.DataBean> arr = new ArrayList(); private View view; private ListView lv; private Adapter adapter; int i = 0; private PullToRefreshListView pull; private Adapter adapter1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); pull = (PullToRefreshListView) findViewById(R.id.pull); pull.setMode(PullToRefreshBase.Mode.BOTH); ListView lv = pull.getRefreshableView(); adapter1 = new Adapter(); lv.setAdapter(adapter1); new MyAsyncTask().execute("http://www.93.gov.cn/93app/data.do?channelId=0&startNum=0"); pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() { @Override //上拉 public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) { arr.clear(); i = 0; new MyAsyncTask().execute("http://www.93.gov.cn/93app/data.do?channelId=0&startNum=" + i); } @Override //下拉加载20条 public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) { i = i + 20;new MyAsyncTask().execute("http://www.93.gov.cn/93app/data.do?channelId=0&startNum=" + i); } }); } class MyAsyncTask extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... params) { String string = ""; StringBuffer stringBuffer = new StringBuffer(); try { URL url = new URL(params[0]); URLConnection urlConnection = url.openConnection(); InputStream inputStream = urlConnection.getInputStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); while ((string = bufferedReader.readLine()) != null) { stringBuffer.append(string); } } catch (Exception e) { e.printStackTrace(); } return stringBuffer.toString(); } @Override protected void onPostExecute(String s) { super.onPostExecute(s); Jbean fragone_bean = new Gson().fromJson(s, Jbean.class); List<Jbean.DataBean> data = fragone_bean.getData(); arr.addAll(data); adapter1.notifyDataSetChanged(); pull.onRefreshComplete(); } } class Adapter extends BaseAdapter { @Override public int getCount() { return arr.size(); } @Override public Object getItem(int position) { return arr.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { Sj sj = new Sj(); Jbean.DataBean dataBean = arr.get(position); if (convertView==null){ convertView = View.inflate(MainActivity.this,R.layout.pulllist,null); sj.image=convertView.findViewById(R.id.iv); sj.tv=convertView.findViewById(R.id.tv); convertView.setTag(sj); }else { sj =(Sj) convertView.getTag(); } sj.tv.setText(dataBean.getSUBTITLE()); DisplayImageOptions options = new DisplayImageOptions.Builder() .cacheInMemory(true) .cacheOnDisk(true) .showImageOnLoading(R.drawable.zhengzaijiazai) .showImageForEmptyUri(R.drawable.zhengzaijiazai) .showImageOnFail(R.drawable.zhengzaijiazai) .bitmapConfig(Bitmap.Config.RGB_565) .build(); ImageLoader.getInstance().displayImage((String) dataBean.getIMAGEURL(),sj.image,options); return convertView; } } class Sj{ ImageView image; TextView tv; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持VEVB武林网。
ipad mini升级ios8.1卡不卡 ip
上北下南看主板:谈主板南北桥
浅谈数码相机照片发灰的问题
芭蕾舞蹈表演,真实美到极致
下午茶时间,悠然自得的休憩
充斥这繁华奢靡气息的城市迪拜风景图片
从山间到田野再到大海美丽的自然风景图片
肉食主义者的最爱美食烤肉图片
夏日甜心草莓美食图片
人逢知己千杯少,喝酒搞笑图集
搞笑试卷,学生恶搞答题
新闻热点
疑难解答
图片精选
Android基于IJKPlayer视频播放器简
一篇文章弄懂Android自定义viewgro
详解Gradle依赖冲突解决方式
android桌面悬浮窗显示录屏时间控
网友关注