Item  布局

 <?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="120dp">
<ImageView
android:id="@+id/relevantrecommendations_iv"
android:layout_width="150dp"
android:layout_height="120dp"
android:scaleType="center"
android:src="@drawable/psb"
/>
<TextView
android:id="@+id/relevantrecommendations_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="title"
android:textSize="20sp"
/>
</LinearLayout>

MyRecyclerView >> MyAdapter >> ViewHolder

 /*  Project  为一个javaBean*/
public class MyRecyclerView extends RecyclerView{
private Context context;
private List<Project> projectList = new ArrayList<>();
public MyRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.context = context;
initProject();
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
this.setLayoutManager(layoutManager); MyAdapter myAdapter = new MyAdapter(projectList);
this.setAdapter(myAdapter);
}
private void initProject() {
/**
*
* 获取数据
*/
String imageURL = "http://f.hiphotos.baidu.com/image/pic/item/35a85edf8db1cb13f423dfa0d154564e92584b3f.jpg";
String videoURL = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov";
Project project = new Project(1,"AA",imageURL,videoURL,0,0,"BB");
projectList.add(project);
projectList.add(project);
projectList.add(project);
projectList.add(project);
projectList.add(project);
projectList.add(project);
projectList.add(project);
projectList.add(project);
}
class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>{
private List<Project> projectList; public MyAdapter(List<Project> projectList) {
this.projectList = projectList;
} @NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.relevantrecommendationsitem,parent,false);
ViewHolder holder = new ViewHolder(view);
return holder;
} @Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Project project = projectList.get(position);
Glide.with(context).load(project.getImageURL()).into(holder.projectImage);
holder.projectText.setText(project.getTitle());
}
@Override
public int getItemCount() {
return projectList.size();
} public class ViewHolder extends RecyclerView.ViewHolder {
ImageView projectImage;
TextView projectText;
public ViewHolder(View itemView) {
super(itemView);
projectImage = itemView.findViewById(R.id.relevantrecommendations_iv);
projectText = itemView.findViewById(R.id.relevantrecommendations_tv);
}
}
}
}

RecyclerView 可以与CollapsingToolbarLayout一起使用的更多相关文章

  1. 基于MaterialDesign设计风格的妹纸app的简单实现

    代码地址如下:http://www.demodashi.com/demo/11644.html *今天看了郭神的第二行代码,深深的被MaterialDesign的设计风格所吸引,然后就照例做了一个小D ...

  2. CoordinatorLayout, AppBarLayout, CollapsingToolbarLayout使用

    本文介绍Design Support Library中CoordinatorLayout, AppBarLayout, CollapsingToolbarLayout的使用. 先列出了Design S ...

  3. 【转】Android M新控件之AppBarLayout,NavigationView,CoordinatorLayout,CollapsingToolbarLayout的使用

    Android M新控件之AppBarLayout,NavigationView,CoordinatorLayout,CollapsingToolbarLayout的使用 分类: Android UI ...

  4. 安卓Design包之CollapsingToolbarLayout(可折叠的工具栏布局)的简单使用

    转自: CollapsingToolbarLayout的使用 注意:使用前需要添加Design依赖包,使用toolbar时需要隐藏标题头 CollapsingToolbarLayout作用是提供了一个 ...

  5. 【腾讯Bugly干货分享】RecyclerView 必知必会

    本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:http://mp.weixin.qq.com/s/CzrKotyupXbYY6EY2HP_dA 导语 Re ...

  6. CollapsingToolbarLayout

    CollapsingToolbarLayout作用是提供了一个可以折叠的Toolbar,它继承至FrameLayout,给它设置layout_scrollFlags,它可以控制包含在Collapsin ...

  7. DrawerLayout、CoordinatorLayout、CollapsingToolbarLayout的使用--AndroidSupportDesign练手

    先po一张效果图 PS:原谅题主的懒惰吧.. 看着是不是很酷炫,那是因为5.0的动画做得好,代码其实没有多少,搞清楚这个布局的层次关系很重要. 废话不多说了,先来看布局文件 最外层是一个DrawerL ...

  8. Material Design学习-----CollapsingToolbarLayout

    博客引用(http://www.open-open.com/lib/view/open1438265746378.html) CollapsingToolbarLayout为我们提供了一个很方便的顶部 ...

  9. Material Design之CollapsingToolbarLayout使用

    CollapsingToolbarLayout作用是提供了一个可以折叠的Toolbar,它继承至FrameLayout,给它设置layout_scrollFlags,它可以控制包含在Collapsin ...

随机推荐

  1. hdu 1575(矩阵快速幂)

    Tr A Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. LeetCode OJ--Construct Binary Tree from Inorder and Postorder Traversal *

    http://oj.leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ 知道二叉树的中序 ...

  3. npm-debug.log文件出现原因

    项目主目录下总是会出现这个文件,而且不止一个,原因是npm i 的时候,如果报错,就会增加一个此文件来显示报错信息,npm install的时候则不会出现.

  4. delphi中关于时间差的实例

    http://www.cnblogs.com/rogee/archive/2010/09/20/1832035.html 很多时候要用到相差多少天,多少周,多少秒,查了一下资料,整理如下: 首先 us ...

  5. (38)C#IIS

    IIS7.5标识介绍(转) http://www.cnblogs.com/zgqys1980/p/3862815.html 应用程序池的标识是运行应用程序池的工作进程所使用的服务帐户名称.默认情况下, ...

  6. 网络入侵检测规避工具fragrouter

    网络入侵检测规避工具fragrouter   网络入侵检测系统可以通过拦截数据包,获取内容进而判断是否为恶意数据包.对于传输较大的数据包,通常会采用分片的方式,将大数据包拆分为小数据包进行传输.如果入 ...

  7. 分享Kali Linux 2017年第12周镜像文件

    分享Kali Linux 2017年第12周镜像文件 Kali Linux官方于3月19日发布2017年的第12周镜像.这次维持了11个镜像文件的规模.默认的Gnome桌面的4个镜像,E17.KDE. ...

  8. PyTorch学习笔记之Tensors

    PyTorch Tensors are just like numpy arrays, but they can run on GPU.No built-in notion of computatio ...

  9. 数据结构------------------二叉查找树(BST)的java实现

    数据结构------------------二叉查找树(BST)的java实现 二叉查找树(BST)是一种能够将链表插入的灵活性和有序数组查找的高效性相结合的一种数据结构.它的定义如下: 二叉查找树是 ...

  10. List&lt;InvestInfoDO&gt; invest = advertiseDao6.qryInvestInfo(InvestInfoDO1);怎样获得list的实体类;

    List<InvestInfoDO>  invest = advertiseDao6.qryInvestInfo(InvestInfoDO1); 怎样获得List的实体类呢,就是怎样获得I ...