android瀑布流

来源:互联网 发布:java与模式 云盘 编辑:程序博客网 时间:2024/06/05 07:22

Android瀑布流


写一个瀑布流很简单,但是简单的瀑布流也是有一些需要解决的问题,最常见的问题OOM ,图片一旦加载多程序就会崩溃,本工具库使用,SCrollView+LinearLayout实现瀑布流,完美解决oom ,只加载屏幕范围类的图片,图片存在则缓存加载 ,工具经过多次测试,大部分BUG已经解决,

工具库+dome下载   工具库(the_waterfall_flow_view

http://download.csdn.net/detail/qq_18420641/9879236

运行效果图;




工具库说明

the_waterfall_flow_view 文件中有三个包

1 .call_activity;

     flass_img_show.java

2 .dome(封装所需要的对象)

     h_w_dome.java

        ISmartScrollChangedListener.java

        value_dome.java

3.util
     falls_img_loder_util.java
       myImgeView.java
       MyScrollView.java

功能实现实例代码

package test_view;


import java.util.ArrayList;
import java.util.List;


import com.example.test_view.R;


import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import call_activity.flass_img_show;
import dome.value_dome;


public class test_avtivity extends Activity {
LinearLayout lift_img;
LinearLayout center_img;
LinearLayout rigt_img;
value_dome dome;
util.MyScrollView scr_view;


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.test_avtivity_layout);
scr_view = (util.MyScrollView) findViewById(R.id.scr_view);
lift_img = (LinearLayout) findViewById(R.id.lift_img);
center_img = (LinearLayout) findViewById(R.id.center_img);
rigt_img = (LinearLayout) findViewById(R.id.rigt_img);
List<String> url = new ArrayList<String>();


url.add("http://img.hb.aicdn.com/0f553ccde2d182b841eb515bd3dc8e5c3e4055f8837b4-g5JDNR_fw658");
url.add("http://img.hb.aicdn.com/d2d1e96f9ba2f2dc899100afbb046fe02aa682275d8b2-AhseJV_fw658");
url.add("http://img.hb.aicdn.com/05f503e79e197232ac0675f4639cd7459ab4b327bdf37-3HoX31_fw658");


/**
* 参数说明 columnNum 每一次取出多少张图片添加到视图中 img_url 图片的url集合 context上下文
* lift_img,center_img,rigt_img为三个LinearLayout mSmartScrollChangedListener
* 对状态的接口回调(1。ScrollView 滑动到top 2 ScrollView 滑动bottom
* 3,滑动效果是否停止,并判断其中是否有子view到了底部 )
**/

scr_view.showWaterfallView(10, url, test_avtivity.this, lift_img, center_img, rigt_img,
new dome.ISmartScrollChangedListener() {

       //是否滚动到top
@Override
public void onScrolledToTop() {


}
                    //是否滚动到bottom
@Override
public void onScrolledToBottom() {
// TODO Auto-generated method stub

}
                    //是否停止了滚动 ,有没有到达其中一个子view的底部
@Override
public void onScrollStop(boolean ifScrollStop, boolean ifchildShow) {
// TODO Auto-generated method stub


}
});
}


}


布局文件.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <util.MyScrollView
        android:id="@+id/scr_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >


            <LinearLayout
                android:id="@+id/lift_img"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="5"
                android:orientation="vertical" >
            </LinearLayout>


            <LinearLayout
                android:id="@+id/center_img"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="5"
                android:orientation="vertical" >
            </LinearLayout>


            <LinearLayout
                android:id="@+id/rigt_img"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="5"
                android:orientation="vertical" >
            </LinearLayout>
        </LinearLayout>
    </util.MyScrollView>


</LinearLayout>





原创粉丝点击