Volley is used to implement waterfall flow, and volley is used to implement waterfall Flow

Source: Internet
Author: User

Volley is used to implement waterfall flow, and volley is used to implement waterfall Flow

Today, I stopped php and studied the source code of the Volley framework to implement the waterfall flow.

To achieve the final waterfall effect, you need to have some knowledge:

(1) custom layout. To listen for events that slide to the bottom, we need to implement a custom ScrollView and implement a listener through the callback function.

(2) To master the Vollet framework, we need to create a new requestQueue queue. By studying the source code, we can find that the corresponding constructor is input when the queue is created, and then the start method is adjusted, there are four thread pools for sending and receiving requests, each of which implements queue listening in a while loop.

(3) Dynamic Layout: place a LinearLay in the Custom scrollView, calculate the width of each column in the code, and add the ImageView to the layout of each column.

Custom 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);}@Overridepublic boolean onTouch(View view, MotionEvent arg1) {// TODO Auto-generated method stubswitch (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();}}

Implemented java main class

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 {@Overridepublic void onButtom() {// TODO Auto-generated method stubintLayOne();}}@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.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 stublayout1 = 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 stubtime++;if (time > 5)return;for (int i = 0; i < culNum; i++) {ImageRequest imageRequest = new ImageRequest(pics[i],new Listener<Bitmap>() {@Overridepublic void onResponse(Bitmap response) {// TODO Auto-generated method stubImageView 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 stubfor (int i = culNum; i < 2 * culNum; i++) {ImageRequest imageRequest = new ImageRequest(pics[i],new Listener<Bitmap>() {@Overridepublic void onResponse(Bitmap response) {// TODO Auto-generated method stubImageView 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 stubfor (int i = 2 * culNum; i < pics.length; i++) {ImageRequest imageRequest = new ImageRequest(pics[i],new Listener<Bitmap>() {@Overridepublic void onResponse(Bitmap response) {// TODO Auto-generated method stubImageView imageView = new ImageView(getApplicationContext());imageView.setLayoutParams(new LayoutParams(params));imageView.setImageBitmap(response);layout3.addView(imageView);}}, culomWidth, 0, Config.RGB_565, null);queue.add(imageRequest);}}}





Waterfall stream is implemented with details

Based on the AJAX Content Dynamic Loading technology, waterfall streams are only layout, and content must be dynamically loaded through AJAX, that is, unlimited drop-down.

You can see the image display of IMG 51 tietu,

How does Dreamweaver implement waterfall stream?

First of all, dreamweaver is a programming tool, while waterfall stream is a program effect written by language. dreamweaver will not help you implement complicated applications. you should understand the relationship between the two.
Second, waterfall stream can be compiled by yourself, javascript and other dynamic languages (php asp jsp, etc.), combined with ajax implementation, write yourself a little Complex
Finally, if you use php or java, you can find a similar effect in the ready-made js library. For example, jquery has this plug-in. Just put it on. google the specific plug-in and usage method.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.