package com.dodowaterfall;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import com.dodowaterfall.LazyScrollView.OnScrollListener;
import com.dodowaterfall.widget.FlowTag;
import com.dodowaterfall.widget.FlowView;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;
public class MainActivity extends Activity {
private LazyScrollView waterfall_scroll;
private LinearLayout waterfall_container;
private ArrayList<LinearLayout> waterfall_items;
private Display display;
private AssetManager asset_manager;
private List<String> image_filenames;
private final String image_path = "images";
private Handler handler;
private int item_width;
private int column_count = 4;// 显示列数
private int page_count = 15;// 每次加载15张图片
private int current_page = 0;// 当前页数
private int[] topIndex;// 待用
private int[] bottomIndex;// 待用
private int[] column_height;// 每列的高度
private HashMap<Integer, String> pins;
private int loaded_count = 0;// 已加载数量
private HashMap<Integer, Integer>[] pin_mark = null;
private Context context;
private HashMap<Integer, FlowView> iviews;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
display = this.getWindowManager().getDefaultDisplay();
item_width = display.getWidth() / column_count;// 根据屏幕大小计算每列大小
asset_manager = this.getAssets();
topIndex = new int[column_count];
bottomIndex = new int[column_count];
column_height = new int[column_count];
context = this.getApplicationContext();
iviews = new HashMap<Integer, FlowView>();
pins = new HashMap<Integer, String>();
pin_mark = new HashMap[column_count];
InitLayout();
}
private void InitLayout() {
waterfall_scroll = (LazyScrollView) findViewById(R.id.waterfall_scroll);
waterfall_scroll.getView();
waterfall_scroll.setOnScrollListener(new OnScrollListener() {
@Override
public void onTop() {
// 滚动到最顶端
Log.d("LazyScroll", "Scroll to top");
}
@Override
public void onScroll() {
}
@Override
public void onBottom() {
// 滚动到最低端
AddItemToContainer(++current_page, page_count);
}
@Override
public void onAutoScroll() {
// 暂时解决,需重写
// 自动滚动
Rect bounds = new Rect();
Rect scrollBounds = new Rect(waterfall_scroll.getScrollX(),
waterfall_scroll.getScrollY(), waterfall_scroll
.getScrollX() + waterfall_scroll.getWidth(),
waterfall_scroll.getScrollY()
+ waterfall_scroll.getHeight());
for (int i = 1; i < loaded_count; i++) {
FlowView v = iviews.get(i);
if (v != null) {
v.getHitRect(bounds);
if (Rect.intersects(scrollBounds, bounds)) {
if (v.bitmap == null) {
v.Reload();
}
} else {
v.recycle();
}
}
}
}
});
waterfall_container = (LinearLayout) this
.findViewById(R.id.waterfall_container);
handler = new Handler() {
@Override
public void dispatchMessage(Message msg) {
super.dispatchMessage(msg);
}
@Override
public void handleMessage(Message msg) {
// super.handleMessage(msg);
switch (msg.what) {
case 1:
// Toast.makeText(context, ((FlowView) msg.obj).getHeight(),
// Toast.LENGTH_SHORT).show();
FlowView v = (FlowView) msg.obj;
int w = msg.arg1;
int h = msg.arg2;
Log.d("MainActivity",
String.format(
"获取实际View高度:%d,ID:%d,columnIndex:%d,rowIndex:%d,filename:%s",
v.getHeight(), v.getId(), v
.getColumnIndex(), v.getRowIndex(),
v.getFlowTag().getFileName()));
String f = v.getFlowTag().getFileName();
// 此处计算列值
int columnIndex = GetMinValue(column_height);
v.setColumnIndex(columnIndex);
column_height[columnIndex] += h;
pins.put(v.getId(), f);
iviews.put(v.getId(), v);
break;
}
}
@Override
public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
return super.sendMessageAtTime(msg, uptimeMillis);
}
};
waterfall_items = new ArrayList<LinearLayout>();
for (int i = 0; i < column_count; i++) {
LinearLayout itemLayout = new LinearLayout(this);
LinearLayout.LayoutParams itemParam = new LinearLayout.LayoutParams(
item_width, LayoutParams.WRAP_CONTENT);
itemLayout.setPadding(2, 2, 2, 2);
itemLayout.setOrientation(LinearLayout.VERTICAL);
itemLayout.setLayoutParams(itemParam);
waterfall_items.add(itemLayout);
waterfall_container.addView(itemLayout);
}
// 加载所有图片路径
try {
image_filenames = Arrays.asList(asset_manager.list(image_path));
} catch (IOException e) {
e.printStackTrace();
}
// 第一次加载
AddItemToContainer(current_page, page_count);
}
private void AddItemToContainer(int pageindex, int pagecount) {
int currentIndex = pageindex * pagecount;
// 将废弃:按照顺序排列图片,发现问题,如果图片不均匀则会出现有的列过长有的列短的情况
// 将采用根据高度最小的那列添加图片的方式
int j = currentIndex % column_count;
int imagecount = image_filenames.size();
for (int i = currentIndex; i < pagecount * (pageindex + 1)
&& i < imagecount; i++) {
loaded_count++;
j = j >= column_count ? j = 0 : j;
// j = GetMinValue(column_height);
AddImage(image_filenames.get(i), j++,
(int) Math.ceil(loaded_count / (double) column_count),
loaded_count);
}
}
private void AddImage(String filename, int columnIndex, int rowIndex, int id) {
FlowView item = (FlowView) LayoutInflater.from(this).inflate(
R.layout.waterfallitem, null);
item.setColumnIndex(columnIndex);
item.setRowIndex(rowIndex);
item.setId(id);
item.setViewHandler(this.handler);
// 多线程参数
FlowTag param = new FlowTag();
param.setFlowId(id);
param.setAssetManager(asset_manager);
param.setFileName(image_path + "/" + filename);
param.setItemWidth(item_width);
item.setFlowTag(param);
item.LoadImage();
waterfall_items.get(columnIndex).addView(item);
}
private int GetMinValue(int[] array) {
int m = 0;
int length = array.length;
for (int i = 0; i < length; ++i) {
if (array[i] < array[m]) {
m = i;
}
}
return m;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android瀑布流实现,类似于蘑菇街和迷尚 应用里的排列.zip
共167个文件
jpg:150个
xml:5个
java:5个
0 下载量 50 浏览量
2023-12-19
17:14:26
上传
评论
收藏 13.05MB ZIP 举报
温馨提示
Android瀑布流实现,类似于蘑菇街和迷尚 应用里的排列.zip
资源推荐
资源详情
资源评论
收起资源包目录
Android瀑布流实现,类似于蘑菇街和迷尚 应用里的排列.zip (167个子文件)
.classpath 364B
MainActivity.java 7KB
FlowView.java 4KB
LazyScrollView.java 3KB
ImageLoaderTask.java 3KB
FlowTag.java 815B
9c4ffc197ca0cf45f298713_p.jpg 90KB
89a208dcec11e0e925183fa_p.jpg 82KB
47bf072c5f9cca1cac41fcd_p.jpg 81KB
6bdc8a9b3530317ab9fbaf2_p.jpg 80KB
3c571e24bc7b123af1e4142_p.jpg 78KB
39cefe4ccf9811a400c9506_p.jpg 77KB
5e03d469cc8a96c6ef7f2ab_p.jpg 77KB
00ba632630100cad1b37a5b_p.jpg 75KB
80df738ee2fe758709b0a1d_p.jpg 73KB
27d8641320d1ede828c62b9_p.jpg 72KB
23b039f6348243b06fa9661_p.jpg 71KB
2eaf3b03a2bb51a6c806eb9_p.jpg 70KB
18da91410fba48b84940a0b_p.jpg 70KB
0c759e15a155c33efbbe267_p.jpg 70KB
7af601b9988b47ea3307622_p.jpg 70KB
9cf3bdf5c43616322ba44eb_p.jpg 69KB
76fee67470d4507a4be4388_p.jpg 68KB
38d1a2fd1173b449371e180_p.jpg 66KB
9cba75ed097b6f707e16c7d_p.jpg 66KB
7ece9d9ebe1c32ec1d09118_p.jpg 65KB
6bfef365ee905510109ec82_p.jpg 65KB
7a6f929741e41a9b943451b_p.jpg 64KB
6b5da1f1df09fa5c3cd1be4_p.jpg 64KB
4e7e20b528ab9586f5411c4_p.jpg 63KB
87dc22d85b16ab8560014a3_p.jpg 63KB
3d538dc25878233920fcff6_p.jpg 61KB
7f30f67a2c822bb72c3e634_p.jpg 61KB
02ceb2d93186e6b59cd2d1a_p.jpg 61KB
0e08be54533cb6802369626_p.jpg 59KB
36c006c6ab2bf10e52ced07_p.jpg 59KB
14eb273c36c2e1d319d60b4_p.jpg 58KB
030e8ae75bc104466c9dfb3_p.jpg 58KB
01f1b3bf86bded07c66e293_p.jpg 57KB
4abfd64cbbb7065e71af313_p.jpg 57KB
21c3ea7bf60dde3f0a80ccd_p.jpg 56KB
9a565e490fa2b0c2c61c1d9_p.jpg 56KB
0b92efc2fef2af6181b47bb_p.jpg 56KB
2f670f8323372f44fcf6c57_p.jpg 56KB
8d4d9e00c91b1ee9c2f937b_p.jpg 56KB
30bf9b43754d7e0d22e3fee_p.jpg 55KB
5cd3c26135f63b6a55c2a73_p.jpg 55KB
41b8c413e16928948bd43be_p.jpg 55KB
2c4aeb4dcc088b05a0b6551_p.jpg 54KB
7c749525697f05e441a99bf_p.jpg 54KB
75f284337a915f654ed9681_p.jpg 54KB
9f16c08828df6ab526ccd33_p.jpg 53KB
7dfab9e19412aa93d5cdc5a_p.jpg 53KB
4f7bbe33cc1417ec3ccda45_p.jpg 53KB
33dfbe8a9fa808a68726449_p.jpg 53KB
1d9917c2b4f6de3ba8206c0_p.jpg 53KB
1b44bb8cf2ad931ac3bd3e7_p.jpg 52KB
16e656e419e8e1002933fa4_p.jpg 52KB
44a8ce077a5f3400f452c95_p.jpg 51KB
4b2eb45fc83817e4413cbc4_p.jpg 51KB
89a5cccff4fff4925c45c7d_p.jpg 50KB
3f23cd4c925671d7bc5cf68_p.jpg 50KB
58cdceec6236f848ec90215_p.jpg 49KB
5d4e0ab4af330b11e16019e_p.jpg 49KB
9d63ee35d128de1d1389019_p.jpg 49KB
44b201e2ec30b0b2cff121d_p.jpg 49KB
9c4957600782e9f9e6b44ed_p.jpg 47KB
6c5ec00caad087a287938c2_p.jpg 47KB
4f5099e4d8df75a2c3a802c_p.jpg 47KB
8e9303dfea4134ba4f23f3b_p.jpg 47KB
9e20c8aa3eeeff7ab7251d9_p.jpg 47KB
82fbb300f1865be79aeb1d1_p.jpg 47KB
0f7c975d3462302f34d1cf8_p.jpg 46KB
9cf1450de5ac3d075131a67_p.jpg 45KB
34eb0041d17eb7de906219c_p.jpg 45KB
7fd74afb22c8e5b57f1b6f9_p.jpg 45KB
22c7bbf8ea85cb59af18e76_p.jpg 45KB
03b2f677350cc8a642121d8_p.jpg 45KB
7b5601e5f10d5fa16141e58_p.jpg 45KB
60bcf7c0f836cdd2e649f86_p.jpg 44KB
4da0d2d88fc0d7516e1573b_p.jpg 44KB
25a05f24b3c5da87d399365_p.jpg 44KB
0e9c98de2b470118883ef7c_p.jpg 43KB
8dc0770c2580b3f731703a1_p.jpg 43KB
5de650117b473863dc374aa_p.jpg 43KB
8c6883cd59a59ad15123287_p.jpg 43KB
012b8593c9782d90fd8a1e3_p.jpg 42KB
1b875e9ac1581c3a912c486_p.jpg 42KB
74b97fc7d1bbdb586406742_p.jpg 42KB
01a377b7944b7a272fc411f_p.jpg 42KB
1e62e847a90d0c2b8614e33_p.jpg 42KB
5ee9650b8222c01ea913ad2_p.jpg 41KB
8bedbfd3d99b8c043d321f0_p.jpg 41KB
58c7c79ae3487a47f44adae_p.jpg 41KB
49c3e7923c17c57739805e0_p.jpg 41KB
3efe42f60f09b163d823f52_p.jpg 41KB
69cbf139a0a90244472b26f_p.jpg 40KB
08ea8c500b978bd38abf08e_p.jpg 39KB
6e15f88e18ae3312e2eeda0_p.jpg 39KB
0aa89e2909bd6efdab6d6c9_p.jpg 38KB
共 167 条
- 1
- 2
资源评论
西江茶客
- 粉丝: 132
- 资源: 1183
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功