android5.0版本推出了新的控件其中CardView则是卡片式布局
效果图:
josn数据:
{"activity": [{"img": "http://pic27.photophoto.cn/20130522/0010023309252566_b.jpg","tiele": "android "},{"img": "http://pic27.photophoto.cn/20130522/0010023309252566_b.jpg","tiele": "java "},{"img": "http://pic27.photophoto.cn/20130522/0010023309252566_b.jpg","tiele": "php "},{"img": "http://pic27.photophoto.cn/20130522/0010023309252566_b.jpg","tiele": "UI"},{"img": "http://pic27.photophoto.cn/20130522/0010023309252566_b.jpg","tiele": "AI"},{"img": "http://pic27.photophoto.cn/20130522/0010023309252566_b.jpg","tiele": "AI"},{"img": "http://pic27.photophoto.cn/20130522/0010023309252566_b.jpg","tiele": "C++"}],"description": "查询成功","flag": "success"}
1、添加依赖
compile files('libs/okhttp-3.0.1.jar') compile files('libs/okio-1.6.0.jar') compile files('libs/picasso-2.5.2.jar') compile 'com.android.support:recyclerview-v7:25.3.1' compile 'com.android.support:cardview-v7:25.3.1'
2、主布局
如果是和Toolbar一起使用,添加下面这段,解决重叠问题
app:layout_behavior="@string/appbar_scrolling_view_behavior"
3、创建RecyclerView的item布局
<?xml version="1.0" encoding="utf-8"?>
其他属性:
app:cardMaxElevation:阴影最大高度app:cardBackgroundColor:卡片的背景app:cardCornerRadius:卡片的圆角大小app:contentPadding:边距
4、主布局Activity代码
public class materialActivity extends AppCompatActivity { public RecyclerView mater_recy; public ArrayList
5、创建适配器
public class material_Adapter extends RecyclerView.Adapter { public Context context; public ArrayList
最后不要忘了添加网络请求权限
- Android开发中WebView与js互相调用
- LayoutInflater.inflate()方法的介绍
- Android(安卓)异步任务加载图片代码
- Android使用HttpClient时出现错误:java.lang.NoSuchFieldError: N
- Android(安卓)ListView(Selector 背景图片 全选 Checkbox等按钮)
- android 开发上传图片遇到返回 FileNotFoundException
- 自己定义的Tabhost
- Android(安卓)学习笔记 Contacts (三)Contacts 查找,增加,更新,删除联
- android中使用local_manifest.xml添加软件
随机推荐
-
android 3d页面跳转
-
Android(安卓)Studio报错:Unsupported met
-
Android(安卓)类似HTML 中Table的网格Tab
-
android WebView载入本地html及css文件
-
Android的NDK开发(4)————JNI数据结构
-
tools for working with android jni
-
android GPS DEMO
-
Android(安卓)沿着线绘制文字
-
Android(安卓)导入项目出错
-
Android(安卓)背光流程小结