采取Volley,实现瀑布流
今天停止php,在研究Volley框架的源代码,实现了瀑布流的效果。
为了实现最终的级联效应,一些需要掌握的知识:
(1)自己定义布局,由于我们要监听滑究竟部的事件就要实现自己定义的ScrollView并通过回调函数实现监听
(2)对Vollet框架的掌握。我们须要新建一个requestQueue队列。通过研究源代码发如今新建这个队列的时候传入对应的构造函数。然后会调整当中的start方法。有四个线程池收发请求。每一个在一个while循环中实现队列的监听。
(3)动态布局。在自己定义的scrollView里面放一个LinearLay然后在代码里面计算每列的宽度,加入ImageView到每列的布局里面。
自己定义的MyScrollView
package com.fallview; import com.android.volley.RetryPolicy; import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ScrollView; public class MyScrollView extends ScrollView implements OnTouchListener { public MyScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
} ScrollTouch scrollTouch; public void setScrollTouch(ScrollTouch touch) {
scrollTouch = touch;
this.setOnTouchListener(this);
} @Override
public boolean onTouch(View view, MotionEvent arg1) {
// TODO Auto-generated method stub switch (arg1.getAction()) {
case MotionEvent.ACTION_DOWN: break;
case MotionEvent.ACTION_UP:
if (view.getMeasuredHeight() <= getHeight() + getScrollY()) {
scrollTouch.onButtom();
} return true; default:
break;
} return false;
} public interface ScrollTouch { public void onButtom();
} }
实现的java主类
package com.fallview; import com.android.volley.RequestQueue;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.ImageRequest;
import com.android.volley.toolbox.Volley;
import com.example.wangyitest.R;
import com.fallview.MyScrollView.ScrollTouch; import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout; public class FallImageAct extends Activity implements PicAdds {
String[] myPics = pics;
LinearLayout linearLayout;
int culomWidth;
int culNum;
RequestQueue queue;
int time = 1; class scrollListener implements ScrollTouch { @Override
public void onButtom() {
// TODO Auto-generated method stub
intLayOne();
}
} @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.falllay);
linearLayout = (LinearLayout) findViewById(R.id.Linearlay);
((MyScrollView) findViewById(R.id.scroll))
.setScrollTouch(new scrollListener());
int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
culomWidth = (screenWidth - 4) / 3;
culNum = myPics.length / 3;
queue = Volley.newRequestQueue(getApplicationContext());
iniadd3Lay();
intLayOne(); } LinearLayout.LayoutParams params; private void iniadd3Lay() {
// TODO Auto-generated method stub
layout1 = new LinearLayout(getApplicationContext());
params = new LinearLayout.LayoutParams(culomWidth,
LinearLayout.LayoutParams.WRAP_CONTENT);
layout1.setPadding(2, 2, 2, 2);
layout1.setOrientation(LinearLayout.VERTICAL);
layout1.setLayoutParams(new LinearLayout.LayoutParams(culomWidth,
LinearLayout.LayoutParams.WRAP_CONTENT));
linearLayout.addView(layout1); layout2 = new LinearLayout(getApplicationContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
culomWidth, LinearLayout.LayoutParams.WRAP_CONTENT);
layout2.setPadding(2, 2, 2, 2);
layout2.setOrientation(LinearLayout.VERTICAL);
layout2.setLayoutParams(new LinearLayout.LayoutParams(culomWidth,
LinearLayout.LayoutParams.WRAP_CONTENT));
linearLayout.addView(layout2); layout3 = new LinearLayout(getApplicationContext());
params = new LinearLayout.LayoutParams(culomWidth,
LinearLayout.LayoutParams.WRAP_CONTENT);
layout3.setPadding(2, 2, 2, 2);
layout3.setOrientation(LinearLayout.VERTICAL);
layout3.setLayoutParams(new LinearLayout.LayoutParams(culomWidth,
LinearLayout.LayoutParams.WRAP_CONTENT));
linearLayout.addView(layout3); } LinearLayout layout1;
LinearLayout layout2;
LinearLayout layout3; private void intLayOne() {
// TODO Auto-generated method stub time++;
if (time > 5)
return; for (int i = 0; i < culNum; i++) {
ImageRequest imageRequest = new ImageRequest(pics[i],
new Listener<Bitmap>() { @Override
public void onResponse(Bitmap response) {
// TODO Auto-generated method stub
ImageView imageView = new ImageView(
getApplicationContext());
imageView.setLayoutParams(new LayoutParams(params));
imageView.setImageBitmap(response);
layout1.addView(imageView);
}
}, culomWidth, 0, Config.RGB_565, null);
queue.add(imageRequest);
} intLayTwo();
} private void intLayTwo() {
// TODO Auto-generated method stub for (int i = culNum; i < 2 * culNum; i++) {
ImageRequest imageRequest = new ImageRequest(pics[i],
new Listener<Bitmap>() { @Override
public void onResponse(Bitmap response) {
// TODO Auto-generated method stub
ImageView imageView = new ImageView(
getApplicationContext());
imageView.setLayoutParams(new LayoutParams(params));
imageView.setImageBitmap(response);
layout2.addView(imageView);
}
}, culomWidth, 0, Config.RGB_565, null);
queue.add(imageRequest);
}
intLaythree();
} private void intLaythree() {
// TODO Auto-generated method stub for (int i = 2 * culNum; i < pics.length; i++) {
ImageRequest imageRequest = new ImageRequest(pics[i],
new Listener<Bitmap>() { @Override
public void onResponse(Bitmap response) {
// TODO Auto-generated method stub
ImageView imageView = new ImageView(
getApplicationContext());
imageView.setLayoutParams(new LayoutParams(params));
imageView.setImageBitmap(response);
layout3.addView(imageView);
}
}, culomWidth, 0, Config.RGB_565, null);
queue.add(imageRequest);
} }
}
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc2Nib3loal9f/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
版权声明:本文博主原创文章,博客,未经同意不得转载。
采取Volley,实现瀑布流的更多相关文章
- android之Volley实现瀑布流
1.首先我们来看下主布局文件activity_main.xml. <RelativeLayout xmlns:android="http://schemas.android.com/a ...
- jquery瀑布流的制作
首先,还是来看一下炫酷的页面: 今天就边做边说了: 一.准备工作 新建css,js,img文件夹存放相应文件,并在demo.html文件中引入外部文件(注意要把jquery文件引入),这里就不过多描述 ...
- js瀑布流 原理实现揭秘 javascript 原生实现
web,js瀑布流揭秘 瀑布流再很久之前流行,可能如我一样入行晚的 ,可能就没有机会去使用.但是这个技术终究是个挺炫酷的东西,花了一个上午来研究,用原生js实现了一个,下面会附上源码,供大家解读. 说 ...
- CollectionView水平和竖直瀑布流的实现
最近在项目中需要实现一个水平的瀑布流(即每个Cell的高度是固定的,但是长度是不固定的),因为需要重写系统 UICollectionViewLayout中的一些方法通过计算去实现手动布局,所以本着代码 ...
- 用jquery实现瀑布流案例
一.瀑布流是我们常见的案例,这里主要讲述,用jquery的方式实现瀑布流的功能! 引言:我们经常见到很多网站的瀑布流功能,如淘宝.京东这些商品等等.. 实现它我们首先考虑几个问题:1.获取到数据 ...
- RecylerView完美实现瀑布流效果
RecylerView包含三种布局管理器,分别是LinearLayoutManager,GridLayoutManager,StaggeredGridLayoutManager,对应实现单行列表,多行 ...
- 飞流直下的精彩 -- 淘宝UWP中瀑布流列表的实现
在淘宝UWP中,搜索结果列表是用户了解宝贝的重要一环,其中的图片效果对吸引用户点击搜索结果,查看宝贝详情有比较大的影响.为此手机淘宝特意在搜索结果列表上采用了2种表现方式:一种就是普通的列表模式,而另 ...
- iOS瀑布流实现(Swift)
这段时间突然想到一个很久之前用到的知识-瀑布流,本来想用一个简单的方法,发现自己走入了歧途,最终只能狠下心来重写UICollectionViewFlowLayout.下面我将用两种方法实现瀑布流,以及 ...
- 瀑布流StaggeredGridView 下拉刷新
1.项目中用到了瀑布流,之前用的是PinterestLikeAdapterView这个控件 然后上拉加载更多跟下拉刷新用的是XListView ,但是加载更多或者下拉刷新的时候闪屏,对用户体验很不好 ...
随机推荐
- .NET开发必看资料53个+经典源码77个
目录0豆下载:http://down.51cto.com/data/426019 附件预览: 基于.net构架的留言板项目大全源码 http://down.51cto.com/zt/70 ASP.ne ...
- restrictkeyword
今天在移植ffmpeg到opencore时出现一个编译错误: /libavcodec/dsputil.c:545: error: expected ';', ',' or ')' before 'bl ...
- hadoop学习;自己定义Input/OutputFormat;类引用mapreduce.mapper;三种模式
hadoop切割与读取输入文件的方式被定义在InputFormat接口的一个实现中.TextInputFormat是默认的实现,当你想要一次获取一行内容作为输入数据时又没有确定的键.从TextInpu ...
- 黄聪:Microsoft Enterprise Library 5.0 系列教程(三) Validation Application Block (高级)
原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(三) Validation Application Block (高级) 企业库验证应用程序模块之配置文件模式: ...
- Windows Phone开发(42):缓动动画
原文:Windows Phone开发(42):缓动动画 前面在讨论关键帧动画的时候,我有意把几个带缓动动画的关键帧动画忽略掉,如EasingColorKeyFrame.EasingDoubleKeyF ...
- POJ 1146:ID Codes
ID Codes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6281 Accepted: 3769 Description ...
- python可变参数调用函数的问题
已使用python实现的一些想法,近期使用python这种出现的要求,它定义了一个函数,第一种是一般的参数,第二个参数是默认,并有可变参数.在第一项研究中python时间,不知道keyword可变参数 ...
- linux 流量监控 ---iptraf的安装及使用
一.安装iptraf 我用的是centos,切换到root用户,执行 yum install -y iptraf 二.使用 1.直接输入iptraf,进入软件,按任意键继续 2.我主要是第二项和第三项 ...
- 1pdf
Document doc = new Document(new iTextSharp.text.Rectangle(564, 351)); PdfWriter writer= PdfWriter.G ...
- 重新想象 Windows 8 Store Apps (17) - 控件基础: Measure, Arrange, GeneralTransform, VisualTree
原文:重新想象 Windows 8 Store Apps (17) - 控件基础: Measure, Arrange, GeneralTransform, VisualTree [源码下载] 重新想象 ...