今天停止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,实现瀑布流的更多相关文章

  1. android之Volley实现瀑布流

    1.首先我们来看下主布局文件activity_main.xml. <RelativeLayout xmlns:android="http://schemas.android.com/a ...

  2. jquery瀑布流的制作

    首先,还是来看一下炫酷的页面: 今天就边做边说了: 一.准备工作 新建css,js,img文件夹存放相应文件,并在demo.html文件中引入外部文件(注意要把jquery文件引入),这里就不过多描述 ...

  3. js瀑布流 原理实现揭秘 javascript 原生实现

    web,js瀑布流揭秘 瀑布流再很久之前流行,可能如我一样入行晚的 ,可能就没有机会去使用.但是这个技术终究是个挺炫酷的东西,花了一个上午来研究,用原生js实现了一个,下面会附上源码,供大家解读. 说 ...

  4. CollectionView水平和竖直瀑布流的实现

    最近在项目中需要实现一个水平的瀑布流(即每个Cell的高度是固定的,但是长度是不固定的),因为需要重写系统 UICollectionViewLayout中的一些方法通过计算去实现手动布局,所以本着代码 ...

  5. 用jquery实现瀑布流案例

    一.瀑布流是我们常见的案例,这里主要讲述,用jquery的方式实现瀑布流的功能! 引言:我们经常见到很多网站的瀑布流功能,如淘宝.京东这些商品等等.. 实现它我们首先考虑几个问题:1.获取到数据   ...

  6. RecylerView完美实现瀑布流效果

    RecylerView包含三种布局管理器,分别是LinearLayoutManager,GridLayoutManager,StaggeredGridLayoutManager,对应实现单行列表,多行 ...

  7. 飞流直下的精彩 -- 淘宝UWP中瀑布流列表的实现

    在淘宝UWP中,搜索结果列表是用户了解宝贝的重要一环,其中的图片效果对吸引用户点击搜索结果,查看宝贝详情有比较大的影响.为此手机淘宝特意在搜索结果列表上采用了2种表现方式:一种就是普通的列表模式,而另 ...

  8. iOS瀑布流实现(Swift)

    这段时间突然想到一个很久之前用到的知识-瀑布流,本来想用一个简单的方法,发现自己走入了歧途,最终只能狠下心来重写UICollectionViewFlowLayout.下面我将用两种方法实现瀑布流,以及 ...

  9. 瀑布流StaggeredGridView 下拉刷新

    1.项目中用到了瀑布流,之前用的是PinterestLikeAdapterView这个控件  然后上拉加载更多跟下拉刷新用的是XListView ,但是加载更多或者下拉刷新的时候闪屏,对用户体验很不好 ...

随机推荐

  1. 静默安装MSSQL

    原文地址:http://www.cnblogs.com/lyhabc/p/3511788.html 介绍 假如你有50台服务器需要安装SQLSERVER,如果你用下一步下一步的方式,用远程桌面不停切换 ...

  2. linux crontab定时执行shell脚本

    linux下使用crontab命令被用来提交和管理用户的需要周期性执行的任务,示例如下:crontab -e 编辑周期任务30 21 * * * /etc/init.d/smb restart 每晚的 ...

  3. 每日算法之三十三:Trapping Rain Water

    这是一个非常有意思的问题,求解最大容积问题,值得动脑筋想一想. 原题例如以下: Given n non-negative integers representing an elevation map ...

  4. OpenCV两张图片的合并

    转载请注明出处..! http://blog.csdn.net/zhonghuan1992 OpenCV两张图片的合并 原理: 两张图片合并,想想图片是用一个个像素点来存储.每一个像素点有他的值. 那 ...

  5. linux提取锁和信号灯经常使用

    1.信号( 这两个过程之间的同步) struct semaphore power_sem; sema_init(&pdata->power_sem,1); down(&pdata ...

  6. J2SE基础:1.类和对象基础

    什么是对象 在Java语言,全部的人,事物或者模块都是一个对象. 同样的对象具有一些同样的特性. 狗,猫,蛇3个对象(动物的对象) 苹果,梨,桔子3个对象(水果的对象) 什么是类 能够将现实生活中的对 ...

  7. cocos2d-x坐标系

    在cocos2d-x在,有几种不同的坐标系. 因为有好几个坐标系着一定的差异,他们需要明白,能力更精确的绘制各种图形画面上. 1.屏幕坐标系 只windows通过绘制图形上基本都知道.相应的坐标系统: ...

  8. client对象层次和0级DOM

    刚開始学了两天JS,闲着无聊,顺手画了张图

  9. MVC区域 vs2013 mvc 搭建基架项

    http://www.it165.net/pro/html/201404/12822.html

  10. Linux日志清除

    因为数据要求.经常需要抓住和筛选过滤数据,大概花了7 8个月.改变了机旁数据.重新开始,发现"No space left on device" 解决方法: 直接删除日志(简单粗暴) ...