今年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)新特性介绍(一)的更多相关文章

  1. php5.3到php7.0.x新特性介绍

    <?php /*php5.3*/ echo '<hr>'; const MYTT = 'aaa'; #print_r(get_defined_constants()); /* 5.4 ...

  2. OpenNebula 4.0 Beta 新特性介绍

    http://blog.chinaunix.net/uid-20940095-id-3561376.html 2013年3月26号,OpenNebula社区发布了OpenNebula 4.0 Beta ...

  3. Hive2.0的新特性介绍

  4. Hadoop3.0新特性介绍,比Spark快10倍的Hadoop3.0新特性

    Hadoop3.0新特性介绍,比Spark快10倍的Hadoop3.0新特性 Apache hadoop 项目组最新消息,hadoop3.x以后将会调整方案架构,将Mapreduce 基于内存+io+ ...

  5. webpack 4.0.0-beta.0 新特性介绍

    webpack 可以看做是模块打包机.它做的事情是:分析你的项目结构,找到JavaScript模块以及其它的一些浏览器不能直接运行的拓展语言(Scss,TypeScript等),并将其打包为合适的格式 ...

  6. Pivotal Greenplum 6.0 新特性介绍

    Pivotal Greenplum 6.0 新特性介绍   在1月12日举办的Greenplum开源有道智数未来技术研讨会上,Pivotal中国研发中心Greenplum 产品经理李阳向大家介绍了Pi ...

  7. [转帖]Pivotal Greenplum 6.0 新特性介绍

    Pivotal Greenplum 6.0 新特性介绍 https://cloud.tencent.com/developer/news/391063 原来 greenplum 也是基于pg研发的. ...

  8. Android5.0(Lollipop) BLE蓝牙4.0+浅析code(二)

    作者:Bgwan链接:https://zhuanlan.zhihu.com/p/23347612来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. Android5.0(L ...

  9. dubbox新特性介绍

    dubbx是当当网对原阿里dubbo2.x的升级,并且兼容原有的dubbox.其中升级了zookeeper和spring版本,并且支持restfull风格的远程调用. dubbox git地址:  h ...

随机推荐

  1. ixcache的蜜汁突发故障

    公元2018年 7月29日 晚上21点整,我司一直正常运行的ixcache线路异常断开. ??? 公司业务包含提供互联网接入服务,所以这个现象将会导致用户上网体验变差,网速变慢,看视频的速度下降等等, ...

  2. 如何用纯 CSS 创作 404 文字变形为 NON 文字的交互特效

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/ZoxjXm 可交互视频教 ...

  3. 性能优化 java 24 次阅读 · 读完需要 15 分钟 0

    摘要: 技术传播的价值,不仅仅体现在通过商业化产品和开源项目来缩短我们构建应用的路径,加速业务的上线速率,也会体现在优秀程序员在工作效率提升.产品性能优化和用户体验改善等小技巧方面的分享,以提高我们的 ...

  4. c++_方格填数(最新方法)

      方格填数 如下的10个格子 +--+--+--+ | | | |+--+--+--+--+| | | | |+--+--+--+--+| | | |+--+--+--+ (如果显示有问题,也可以参 ...

  5. nginx 配置虚拟机 支持pathinfo

    server { server_name shopx.local *.shopx.local; charset utf-8; root /Users/x/www/php/shopx.local/sho ...

  6. luogu3168 [CQOI2015]任务查询系统

    树状数组不用动脑子真爽啊 #include <algorithm> #include <iostream> #include <cstdio> using name ...

  7. .net对象的生命周期

    阅读了文章:.NET对象生命周期小结 文章分多个部分,第一部分:介绍了,创建对象时,内存的分配,对象真正被创建,以及经历各阶段垃圾回收的过程. 第二部分,介绍了Finalize与Dispsose方法.

  8. 1284-Primitive Roots,学信安的路过

                                                      Primitive Roots 此题通过率如此之高,料想不会很难,但是再简单小菜还是不会.. 嗯,下 ...

  9. [BZOJ4052][Cerc2013]Magical GCD

    [BZOJ4052][Cerc2013]Magical GCD 试题描述 给出一个长度在 100 000 以内的正整数序列,大小不超过 10^12.  求一个连续子序列,使得在所有的连续子序列中,它们 ...

  10. HDU 1102 Kruscal算法

    题目大意:给定村庄的数量,和一个矩阵表示每个村庄到对应村庄的距离,矩阵主对角线上均为1 在给定一个数目Q,输入Q行之间已经有通道的a,b 计算还要至少修建多少长度的轨道 这道题目用Kruscal方法进 ...