Android之RecyclerView实现时光轴

阅读更多

做项目的过程中有个需求需要时光轴,于是网上找了部分资料 ,写了个案例,现在分享给大家。

如图:

Android之RecyclerView实现时光轴_第1张图片

activity_main.xml

 




    


item.xml



    

    

        

        

    

    

    
    


Activity.Java

public class MainActivity extends AppCompatActivity {

    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initLayout();
    }
    private void initLayout(){
        recyclerView= (RecyclerView) findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setHasFixedSize(true);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        initData();
    }
    private void initData(){
        List list=new ArrayList<>();
        for(int i=0;i<15;i++){
            list.add(new TimeInfo());
        }
        TimelineAdapter mAdapter = new TimelineAdapter(this, list);
        recyclerView.setAdapter(mAdapter);
    }
}

 

添加依赖库:

 

 

compile 'com.android.support:recyclerview-v7:23.0.0'

 

 

由于代码太多,完整代码未给出,源码直接下载即可

 

源码点击下载

 

 

 

你可能感兴趣的:(Android,时光轴,RecyclerView,列表,时间轴)