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 ...
随机推荐
- Node.js 创建server服务器
var http=require('http'); //引入http模块 var server=http.createServer(function(req,res){ //创建一个server r ...
- 安装Yii2提示Failed to decode response: zlib_decode(): data error错误解决方法
如果是根据官方文档来安装(composer create-project --prefer-dist yiisoft/yii2-app-basic basic),并提示此错误的话,那么请做: 1. 请 ...
- python基础教程之pymongo库
1. 引入 在这里我们来看一下Python3下MongoDB的存储操作,在本节开始之前请确保你已经安装好了MongoDB并启动了其服务,另外安装好了Python的PyMongo库. 1. 安装 pi ...
- C语言学习9
婚礼的谎言 三对情侣参加婚礼,三个新郎为A.B.C,三个新娘为X.Y.Z.有人想知道究竟水域谁结婚2,于是就问新人中的三位,得到结果如下:A说他将和X结婚:X说她的未婚夫是C:C说他将和Z结婚.这人事 ...
- .NET如何进行数据库连接
在.net中连接sql server数据库,需引入System.Data.SqlClient命名空间: 1,最简单的连接方式: SqlConnection conn = new SqlConnecti ...
- selenium,phantomJS,python整合的一个小示例,把某个网页画面整体保存成图片格式。
本篇将使用selenium,phantomJS和python制作的一个示例,把某个网页整体保存为一个图片文件. 简单介绍下,selenium是一个开源的用于测试web程序的工具,当然,如果你要执行一些 ...
- Sticky footer经典布局--绝对底部布局
原文转载于:https://cnodejs.org/topic/56ebdf2db705742136388f71 何为Sticky footer布局? 我们常见的网页布局方式一般分为header(页头 ...
- 集合框架学习之List接口
Java语言的java.util包中提供了一些集合类,这些集合类又被称为容器.用来完善数组的不足之处.集合类与数组的不同之处是,数组的长度是固定的,集合的长度是可变的:数组用来存放基本类型的数据,集合 ...
- 大数据学习——JAVA采集程序
1 需求 从外部购买数据,数据提供方会实时将数据推送到6台FTP服务器上,我方部署6台接口采集机来对接采集数据,并上传到HDFS中 提供商在FTP上生成数据的规则是以小时为单位建立文件夹(2016-0 ...
- Ext修改Confirm弹框按钮的默认值