灭霸-个人冲刺第三天

1, 昨天的成就:

  a)       完成的任务:设置主页面,实现瀑布流

  b)       所花时间:5h

  c)        还剩余1h

2, 遇到的困难:

  a)       瀑布流需要一宽一长,同时照片各不一样

  b)       照片自动更改尺寸

3, 今天的任务:

  a)       架设框架

  b)       处理数据库

package com.example.a13313.瀑布流;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.a13313.R;

/**
 * Created by 13313 on 2019/4/21.
 */
public class StaggeredGridAdapter extends RecyclerView.Adapter<StaggeredGridAdapter.LinearViewHolder> {
    private Context mContext;
    private OnItemClickListener mlistener;  //分配空间
    //private List<String> list;
    public StaggeredGridAdapter(Context context, OnItemClickListener listener){
        this.mContext=context;             //内容
        this.mlistener=listener;          //传输位置
    }
    @NonNull
    @Override
    public StaggeredGridAdapter.LinearViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new LinearViewHolder(LayoutInflater.from(mContext).inflate(R.layout.layout_staggered_grid_recyclerview_item,viewGroup,false));
    }

    @Override
    public void onBindViewHolder(@NonNull StaggeredGridAdapter.LinearViewHolder viewHolder, final int i) {
        if(i%2!=0)
        viewHolder.imageView.setImageResource(R.drawable.mo); //内容
        else
            viewHolder.imageView.setImageResource(R.drawable.people);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {  //监听器按键
            @Override
            public void onClick(View v) {
                mlistener.onClick(i);       //监听器
            }
        });
    }

    @Override
    public int getItemCount() {
        return 30;
    }
    class LinearViewHolder extends RecyclerView.ViewHolder{
    private ImageView imageView;
        public LinearViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView=(ImageView) itemView.findViewById(R.id.iv);
        }
    }
    public interface OnItemClickListener{  //字节型监听器
        void onClick(int pos);

    }
}

 

posted @ 2019-05-03 19:51  博二爷  阅读(135)  评论(0编辑  收藏  举报