RecyclerView瀑布流的实现方式

public class StaggAdpter extends RecyclerView.Adapter{
    private Context context;
    private List list;
    private List hiehts = new ArrayList<>();

    public StaggAdpter(Context context, List list) {
        this.context = context;
        this.list = list;
        for(int i = 0;i

 

 

public class TwoActivity extends AppCompatActivity {
   RecyclerView recyclerView;
   StaggAdpter adpter;
   private List list = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);
        recyclerView = findViewById(R.id.re);
        for (int i = 0;i<100;i++){
            list.add("失误");
        }
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, OrientationHelper.VERTICAL));
        adpter = new StaggAdpter(this,list);
        recyclerView.setAdapter(adpter);
    }
    public void add(View view){
        list.add(5,"呵呵");
        adpter.notifyItemInserted(5);
    }
    public void remove(View view){
        list.add(5,"呵呵");
        adpter.notifyItemRemoved(5);
    }
}

你可能感兴趣的:(RecyclerView瀑布流的实现方式)