Android5.0(lollipop)新特性介绍(一)
今年6月的Google I/O大会上。Android L的初次见面我相信让会让非常多android粉丝有些小激动和小期待。当然作为开发人员的我来说,激动不言而喻,毕竟这是自08年以来改变最大的一个版本号。
新的设计语言(Material Design),5000多个新增api。废话不多说,今天要说的基本都是在Android5.0中非经常见。也算是对自己学习的一种记录。
1.CardView
顾名思义,CardView 卡片视图。继承自framelayout。能够通过设置圆角以及阴影来展示带有像卡片一样的效果
使用方法:在布局声明CardView(注意:须要引入android-support-v7-cardview.jar)
<span style="font-size:14px;"><android.support.v7.widget.CardView
android:id="@+id/cardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:elevation="100dp"
card_view:cardBackgroundColor="@color/cardview_initial_background"
card_view:cardCornerRadius="8dp"
android:layout_marginLeft="@dimen/margin_large"
android:layout_marginRight="@dimen/margin_large">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_medium"
android:text="@string/cardview_contents"/>
</android.support.v7.widget.CardView></span>
在Activity中通过调用mCardView.setRadius(progress)与mCardView.setElevation(progress)方法来分别设置CardView的圆角和阴影。
2.RecyclerView
RecyclerView的出现能够替代ListView和GridView。它标准化了ViewHolder。之前我们在写ListView的Adapter时需要自己定义ViewHolder来提升ListView速度。
使用RecyclerView的时候必需要设置LayoutManager,它会通知系统以什么样的布局来展示RecyclerView,眼下系统提供了2种LayoutManager,LinearLayoutManager和GridLayoutManager相应着线性和格子,当然了也能够自己定义LayoutManager来满足各种需求
使用方法:布局文件里声明RecyclerView(注意:须要引入android-support-v7-recyclerview.jar)
<span style="font-size:14px;"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:checkedButton="@+id/linear_layout_rb">
<RadioButton android:id="@+id/linear_layout_rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/linear_layout_manager"/>
<RadioButton android:id="@+id/grid_layout_rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/grid_layout_manager"/>
</RadioGroup> <android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout></span>
在Activity中调用例如以下代码
<span style="font-size:14px;">mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
//相似listview
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
//相似grdiview
mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 3));
mAdapter = new CustomAdapter(mDataset);
// Set CustomAdapter as the adapter for RecyclerView.
mRecyclerView.setAdapter(mAdapter);</span>
CustomAdapter代码例如以下
<span style="font-size:14px;">public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {
private static final String TAG = "CustomAdapter"; private String[] mDataSet; /**
* Provide a reference to the type of views that you are using (custom ViewHolder)
*/
public static class ViewHolder extends RecyclerView.ViewHolder {
private final TextView textView; public ViewHolder(View v) {
super(v);
// Define click listener for the ViewHolder's View.
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
textView = (TextView) v.findViewById(R.id.textView);
} public TextView getTextView() {
return textView;
}
} /**
* Initialize the dataset of the Adapter.
*
* @param dataSet String[] containing the data to populate views to be used by RecyclerView.
*/
public CustomAdapter(String[] dataSet) {
mDataSet = dataSet;
} // Create new views (invoked by the layout manager)
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
// Create a new view.
View v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.text_row_item, viewGroup, false); return new ViewHolder(v);
} // Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
// Get element from your dataset at this position and replace the contents of the view
// with that element
viewHolder.getTextView().setText(mDataSet[position]);
viewHolder.getTextView().setPadding(0, position, 0, 0);
} // Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return mDataSet.length;
}
}</span>
今天先介绍到这里。兴许还会介绍FloatActionBar,触摸反馈,Activity过场动画等。
转载请标注出处,多谢~
Android5.0(lollipop)新特性介绍(一)的更多相关文章
- php5.3到php7.0.x新特性介绍
<?php /*php5.3*/ echo '<hr>'; const MYTT = 'aaa'; #print_r(get_defined_constants()); /* 5.4 ...
- OpenNebula 4.0 Beta 新特性介绍
http://blog.chinaunix.net/uid-20940095-id-3561376.html 2013年3月26号,OpenNebula社区发布了OpenNebula 4.0 Beta ...
- Hive2.0的新特性介绍
- Hadoop3.0新特性介绍,比Spark快10倍的Hadoop3.0新特性
Hadoop3.0新特性介绍,比Spark快10倍的Hadoop3.0新特性 Apache hadoop 项目组最新消息,hadoop3.x以后将会调整方案架构,将Mapreduce 基于内存+io+ ...
- webpack 4.0.0-beta.0 新特性介绍
webpack 可以看做是模块打包机.它做的事情是:分析你的项目结构,找到JavaScript模块以及其它的一些浏览器不能直接运行的拓展语言(Scss,TypeScript等),并将其打包为合适的格式 ...
- Pivotal Greenplum 6.0 新特性介绍
Pivotal Greenplum 6.0 新特性介绍 在1月12日举办的Greenplum开源有道智数未来技术研讨会上,Pivotal中国研发中心Greenplum 产品经理李阳向大家介绍了Pi ...
- [转帖]Pivotal Greenplum 6.0 新特性介绍
Pivotal Greenplum 6.0 新特性介绍 https://cloud.tencent.com/developer/news/391063 原来 greenplum 也是基于pg研发的. ...
- Android5.0(Lollipop) BLE蓝牙4.0+浅析code(二)
作者:Bgwan链接:https://zhuanlan.zhihu.com/p/23347612来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. Android5.0(L ...
- dubbox新特性介绍
dubbx是当当网对原阿里dubbo2.x的升级,并且兼容原有的dubbox.其中升级了zookeeper和spring版本,并且支持restfull风格的远程调用. dubbox git地址: h ...
随机推荐
- 洛谷——P3801 红色的幻想乡
P3801 红色的幻想乡 推荐阅读 https://blog.csdn.net/qq_41252892/article/details/79035942 非常清楚 线段树单点修改 emmm没什么了 # ...
- POJ-1328-放置雷达
这是一道贪心的题目,首先我们要知道,我们放置雷达的话我们可以做一个转换,就是已知岛屿的点坐标的时候,我们可以算一下,这个点以d为半径与x轴交点之间的线段在x轴上的投影,然后我们只需要在这个投影范围内设 ...
- (8) openssl rsautl(签名/验证签名/加解密文件)和openssl pkeyutl(文件的非对称加密)
rsautl是rsa的工具,相当于rsa.dgst的部分功能集合,可用于生成数字签名.验证数字签名.加密和解密文件. pkeyutl是非对称加密的通用工具,大体上和rsautl的用法差不多,所以此处只 ...
- CSS3---媒体查询与响应式布局
1. 值 设备类型 All 所有设备 Braille 盲人用点字法触觉回馈设备 Embossed 盲文打印机 Handheld 便携设备 Print 打印用纸或打印预览视图 Projection 各种 ...
- Django框架基础知识06-模型基础
1.数据库的连接配置 django 连接mysql的配置流程: 安装 pymysql pip install pymysql 创建数据库用户 有创建数据库权限的用户 创建数据库 crm 修改配置 se ...
- 2019年,Python工程师必考的6个面试题,Python面试题No5
第1题:Python里面如何实现tuple和list的转换? 函数tuple(seq)可以把所有可迭代的(iterable)序列转换成一个tuple, 元素不变,排序也不变 list转为tuple: ...
- Java多线程入门Ⅱ
线程的让步 线程让出自己占用的CPU资源 线程让出资源,不指定让给谁 线程让出资源,指定让给谁 方法1: public static void yield(); 线程实现交替打印 import jav ...
- luogu2485 [SDOI2011]计算器 poj3243 Clever Y BSGS算法
BSGS 算法,即 Baby Step,Giant Step 算法.拔山盖世算法. 计算 \(a^x \equiv b \pmod p\). \(p\)为质数时 特判掉 \(a,p\) 不互质的情况. ...
- 用python写自定义模板
模板语法有点像php !/usr/bin/env python """ #demo.py.html <html> <?py include head.p ...
- js总结(一):javascript的类型:基本类型、对象和数组
javascript 类型分为2种,一个是原始值,另一个是复杂值(对象). 一.原始值 5个原始值是:数字,字符,布尔,null,undefined. 9个原生的对象构造函数:Number Strin ...