今天停止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. 对consistencygroup的一些研究和实践

    声明: 本博客欢迎转载,但请保留原作者信息! 作者:李人可 团队:华为杭州OpenStack团队 consistency group,直译是一致性组,是Juno版本号cinder新引进的一个概念.顾名 ...

  2. C#区域截图——调用API截图

    原文:C#区域截图——调用API截图 前言:截图对于一个C++开发者来说无非是小菜一碟,也有朋友使用C#的 Graphics.CopyFromScreen 方法屏幕操作,作为一名整天想着用 C++ 开 ...

  3. 不用Root权限获取已经安装的Apk安装包

    在安卓设备上安装的apk都会被保留一份在/data/app目录下,但是该目录对于普通用户来说只有可执行权限,是无法访问的. 但是其子文件具有可读权限. 意思也就说我们直接去查看/data/app这个目 ...

  4. 鸽巢原理应用-分糖果 POJ 3370 Halloween treats

    基本原理:n+1只鸽子飞回n个鸽笼至少有一个鸽笼含有不少于2只的鸽子. 很简单,应用却也很多,很巧妙,看例题: Description Every year there is the same pro ...

  5. Android ImageButton Example 图片按钮

    Android ImageButton Example 图片按钮 使用“android.widget.ImageButton” 展现一个具有背景图片的按钮 本教程将展现一个具有名字为 c.png背景图 ...

  6. 1104. Don’t Ask Woman about Her Age(数论)

    a*b^n(mod(b-1) =a(mod(b-1) http://acm.timus.ru/problem.aspx?space=1&num=1104 #include <stdio. ...

  7. 优化数据页面(18)——标注keyword

    优化数据页面(18)--标注keyword 设计要点:优化数据页面.界面设计.美化exce 秀秀:事实上俺认为,相同是数据项,它们的重要程度也不同. 阿金:嗯? 秀秀:每一行数据时描写叙述一条信息的, ...

  8. 设计模式C++达到 3.抽象工厂

    简单工厂模式和工厂模式 要求 同类型的产品子类有共同的方法.这限制了产品子类的扩展.抽象工厂能client它提供了一个接口,它是client而不必指定产品的详细信息.创建多个产品系列产品对象.在归为一 ...

  9. 通常编译亲测56Y国际象棋源代码,精仿56Y国际象棋完整的源代码下载!

    今天公布亲测通常应编译56Y国际象棋源代码,精仿56Y牌源代码.喜欢的能够拿去研究.论坛资源太多.我们会把好的资源都公布出来,同一时候欢迎很多其它的程序猿增加我们! 增加我们的共同学习交流!     ...

  10. 深挖BAT内部级别和薪资待遇,你敢看?(转)

    一. 阿里内部级别和薪资待遇 先看个例子,或许你也曾像他一样纠结 BAT 的 offer: 最近刚通过阿里面试,但基本薪酬也是不升反小降. 级别只有 P6+,连 P7 都没有,非常郁闷,打算拒绝算了. ...