今天停止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. Keepalived+LVS+Nginx负载均衡之高可用

    Keepalived+LVS+Nginx负载均衡之高可用 上一篇写了nginx负载均衡,此篇实现高可用(HA).系统整体设计是采用Nginx做负载均衡,若出现Nginx单机故障,则导致整个系统无法正常 ...

  2. 数据库关于group by 两个或以上条件的分析

    首先group by 的简单说明:    group by 一般和聚合函数一起使用才有意义,比如 count sum avg等,使用group by的两个要素:    (1) 出现在select后面的 ...

  3. ocx控件手动修改clsid的方法

    替换掉工程的两个地方:IDL文件和CTRL文件. IMPLEMENT_OLECREATE_EX(CMultiwndCtrl, "MULTIWND.MultiwndCtrl.1", ...

  4. 64地点 Windows 8/7 根据系统 32地点PLSQL 耦合 64 地点 Oracle 11g

    64地点 Windows 8/7 根据系统 32地点PL/SQL 耦合 64 地点 Oracle 11g     说明:安装后Oracle的 oci.dll 是64位的,而32位应用程序 PL/SQL ...

  5. zigbee学习:示例程序SampleApp中按键工作流程

    zigbee学习:示例程序SampleApp中按键工作流程 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:WIN7 开发环境:IAR8. ...

  6. core graphics path

    当UIKit无法满足画图需求的时候.就须要用到Core Graphics API.当中最普遍的就是path. 一些重要的概念 graphics context 能够理解成canvas.在ios里相应C ...

  7. Java EE (6) -- Java EE 5 Enterprise Architect Certified Master

    Section 1: Application Design Concepts and Principles Explain the main advantages of an object-orien ...

  8. Android:刚6瓶啤酒4两56度白酒下肚,竟然20分钟做了一手机版站点 !

    刚6瓶啤酒4两56度白酒下肚,竟然20分钟不到时间做了一手机版站点 !人有多大潜力你知道吗? 大家有兴趣的能够用手机或微信打开 http://xh.yunxunmi.com/  看看俺这酒后之做! 很 ...

  9. lock订单号

    常见误用场景:在订单支付环节中,为了防止用户不小心多次点击支付按钮而导致的订单重复支付问题,我们用 lock(订单号) 来保证对该订单的操作同时只允许一个线程执行. 这样的想法很好,至少比 lock( ...

  10. 泛泰A860 Andorid4.4.3 KTU84M (Omni) 图赏

    Omni4.4.3 For Pantech A860L/K/S watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3lob3N0/font/5a6L5L2T/ ...