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. python常用模块2

    collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdict. ...

  2. js 去掉以逗号分割的字符串中头尾和中间多余的逗号

    let permission = ",,,106,105,108,,,109,110,107,,101,,," let permission = "106,105,108 ...

  3. Codeforces Gym100735 H.Words from cubes-二分图最大匹配匈牙利

    赛后补题,还是要经常回顾,以前学过的匈牙利都忘记了,“猪队友”又给我讲了一遍... 怎么感觉二分图的匈牙利算法东西好多啊,啊啊啊啊啊啊啊啊啊(吐血...) 先传送一个写的很好的博客,害怕智障找不到了. ...

  4. SD 胡策 Round 1 T3 彩尾巴猹的二进制数

    发现一个区间[L,R]代表的2进制数是3的倍数,当且仅当从L开始的后缀二进制值 - 从R+1开始的后缀二进制值 是 3 的倍数 (具体证明因为太简单而被屏蔽). 于是我们就可以在每个点维护从它开始的后 ...

  5. [JSOI 2015] 子集选取

    4475: [Jsoi2015]子集选取 Time Limit: 1 Sec  Memory Limit: 512 MBSubmit: 363  Solved: 255[Submit][Status] ...

  6. 使用spring声明式事务,spring使用AOP来支持声明式事务,会根据事务属性,自动在方法调用之前决定是否开启一个事务,并在方法执行之后决定事务提交或回滚事务。

    使用spring声明式事务,spring使用AOP来支持声明式事务,会根据事务属性,自动在方法调用之前决定是否开启一个事务,并在方法执行之后决定事务提交或回滚事务.

  7. tensorflow global_variables_initializer()

    老版本为 init = tf.initialize_all_variables() 新版本为 init = tf.global_variables_initializer()

  8. 表现层 JSP 页面实现

    一.实验介绍 1.1 实验内容 本节课程主要利用 easyUI 实现系统的前端页面. 1.2 实验知识点 easyUI JavaScript html 1.3 实验环境 JDK1.8 Eclipse ...

  9. 在jsp中拿到applicationContext

    WebApplicationContext wac = (WebApplicationContext)config.getServletContext().getAttribute(WebApplic ...

  10. Phpstorm 放大字体的快捷键是什么?

      这个功能需要设置才能使用: 步骤:control+shift+A功能可以搜索对应功能 输入mouse 设置Change font size(Zoom) ...的按钮打开,然后就可以通过 ctrl+ ...