Android(Lollipop/5.0) Material Design简介

转载至:http://blog.csdn.net/jjwwmlp456/article/details/40540233#


Material Design系列

Android(Lollipop/5.0) Material Design(一) 简介

Android(Lollipop/5.0) Material Design(二) 入门指南

Android(Lollipop/5.0) Material Design(三) 使用Material主题

Android(Lollipop/5.0) Material Design(四) 创建列表和卡片

Android(Lollipop/5.0) Material Design(五) 定义阴影和裁剪View

Android(Lollipop/5.0) Material Design(六) 使用图片

Android(Lollipop/5.0) Material Design(七) 自定义动画

Android(Lollipop/5.0) Material Design(八) 保持兼容性


官网地址:https://developer.android.com/design/material/index.html

使用Material Design 需要api21,即Lollipop/5.0以上

Material Design 为应用提供了:一个新的主题,一些组合View的新Widget,一些自定义阴影和动画的新Api


Material 主题

   在manifest.xml 中<... android:theme="@android:style/Theme.Material" /> 提示一下有很多相关的主题


详见 使用Material主题


Lists和Cards

5.0提供了两个新的Widget,它们使用了Material Design 的style和animation:

    RecyclerView 一个更可插拔式的ListView,它支持不同的布局类型,并且性能有了改进。     列表式

    CardView 一个能让你在其内显示重要信息,并保持连贯的视觉和感觉的卡片  卡片式

    它两位于 sdk/extras/android/support/v7/cardview 和 sdk/extras/android/support/v7/RecyclerView


详见 创建列表和卡片


View的阴影

  View现在除了x、y属性外还有z,z代表一个view的仰角(elevation, 姑且这么翻译吧)

  z越大,阴影越大;z越大,view会出现在其他view的顶部

详见 定义阴影和裁剪View


动画

新的动画Api,让你在UI控件里能创建触摸反馈,改变View的状态,切换activity的一系列自定义动画

具体有:

响应View的touch事件的触摸反馈动画

隐藏和显示View的循环展示动画

两个Activity间的切换动画

更自然的曲线运动的动画

使用View的状态更改动画,能改变一个或多个View的属性

在View的状态更改时显示状态列表动画

   这些new animations Api,已内置在标准Widget中,如Button。在自定义view时也可使用这些api


详见 使用自定义动画


图片

可伸缩的矢量图片不会丢失清晰度,并且单一颜色的app-icon是完美的

可定义一个bitmap作为透明度(alpha)和运行时的颜色

可对一个bitmap image取色,会取出它比较显眼的颜色

详见 使用图片


附RecyclerView的例子:

[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. import android.app.Activity;  
  2. import android.os.Bundle;  
  3. import android.support.v7.widget.GridLayoutManager;  
  4. import android.support.v7.widget.RecyclerView;  
  5. import android.support.v7.widget.RecyclerView.LayoutParams;  
  6. import android.view.LayoutInflater;  
  7. import android.view.ViewGroup;  
  8. import android.widget.TextView;  
  9.   
  10. public class RecyclerViewActivity extends Activity {  
  11.     /* 
  12.      * recyclerview提供这些内置的布局管理器:  
  13.      * linearlayoutmanager              显示垂直滚动列表或水平的项目。 
  14.      * gridlayoutmanager                显示在一个网格项目。  
  15.      * staggeredgridlayoutmanager       显示在交错网格项目。 
  16.      * 自定义的布局管理器,需要继承recyclerview.layoutmanager类。 
  17.      *  
  18.      * add/remove items时的动画是默认启用的。 
  19.      * 自定义这些动画需要继承RecyclerView.ItemAnimator,并实现RecyclerView.setItemAnimator() 
  20.      */  
  21.      private RecyclerView mRecyclerView;  
  22.      private RecyclerView.Adapter mAdapter;  
  23.      private RecyclerView.LayoutManager mLayoutManager;  
  24.      private String[] myDataset;  
  25.   
  26.     @Override  
  27.     protected void onCreate(Bundle savedInstanceState) {  
  28.         super.onCreate(savedInstanceState);  
  29.           
  30.         setContentView(R.layout.recycler_view);  
  31.         mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);  
  32.   
  33.         // use this setting to improve performance if you know that changes  
  34.         // in content do not change the layout size of the RecyclerView  
  35.         mRecyclerView.setHasFixedSize(true);  
  36.   
  37.         // use a linear layout manager  
  38. //        mLayoutManager = new LinearLayoutManager(this);  
  39.           
  40. //        mLayoutManager = new GridLayoutManager(this, 3, GridLayoutManager.VERTICAL, true);  
  41.         //true 表示,将layout内容反转  
  42.         mLayoutManager = new GridLayoutManager(this3, GridLayoutManager.VERTICAL, false);  
  43.         //HORIZONTAL 横向滚动显示内容   VERTICAL纵向  
  44. //        mLayoutManager = new GridLayoutManager(this, 3, GridLayoutManager.HORIZONTAL, false);  
  45.           
  46.         //方向也是指示滚动方向,例子中横向开头的数据交错了一点, 纵向的无交错  
  47. //        mLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.HORIZONTAL);  
  48. //        mLayoutManager = new StaggeredGridLayoutManager(4, StaggeredGridLayoutManager.VERTICAL);  
  49.           
  50.         mRecyclerView.setLayoutManager(mLayoutManager);  
  51. //        mRecyclerView.setLayoutManager(new MyLayoutMnager()); //数据不显示,可能还需要重写什么东西。。  
  52.   
  53.         // specify an adapter (see also next example)  
  54.         
  55.         setDatas();  
  56.         mAdapter = new MyAdapter(myDataset);  
  57.         mRecyclerView.setAdapter(mAdapter);  
  58.     }  
  59.       
  60.     private void setDatas() {  
  61.         int len = 200;  
  62.         myDataset = new String[len];  
  63.         for (int i = 0; i < len; i++) {  
  64.             switch (i%3) {  
  65.             case 0:  
  66.                 myDataset[i] = "中国" + i;  
  67.                 break;  
  68.             case 1:  
  69.                 myDataset[i] = "美国" + i;  
  70.                 break;  
  71.             case 2:  
  72.                 myDataset[i] = "澳大利亚" + i;  
  73.                 break;  
  74.             }  
  75.         }  
  76.     }  
  77.       
  78.     class MyLayoutMnager extends RecyclerView.LayoutManager {  
  79.   
  80.         @Override  
  81.         public LayoutParams generateDefaultLayoutParams() {  
  82.             LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);  
  83.             params.topMargin = 5;  
  84.             return params;  
  85.         }  
  86.     }  
  87.       
  88.     class MyAdapter extends RecyclerView.Adapter<ViewHolder> {  
  89.         private String[] mDataset;  
  90.   
  91.         // Provide a reference to the views for each data item  
  92.         // Complex data items may need more than one view per item, and  
  93.         // you provide access to all the views for a data item in a view holder  
  94.   
  95.         // Provide a suitable constructor (depends on the kind of dataset)  
  96.         public MyAdapter(String[] myDataset) {  
  97.             mDataset = myDataset;  
  98.         }  
  99.   
  100.         // Create new views (invoked by the layout manager)  
  101.         @Override  
  102.         public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {  
  103.             // create a new view  
  104.             TextView tv = (TextView) LayoutInflater.from(parent.getContext())  
  105.                     .inflate(R.layout.my_text_view, parent, false);  
  106.             // set the view's size, margins, paddings and layout parameters  
  107.             //...  
  108.             ViewHolder vh = new ViewHolder(tv); //构建一个ViewHolder  
  109.             return vh;  
  110.         }  
  111.   
  112.         // Replace the contents of a view (invoked by the layout manager)  
  113.         @Override  
  114.         public void onBindViewHolder(ViewHolder holder, int position) {  
  115.             // - get element from your dataset at this position  
  116.             // - replace the contents of the view with that element  
  117.             holder.mTextView.setText(mDataset[position]);  
  118.   
  119.         }  
  120.   
  121.         // Return the size of your dataset (invoked by the layout manager)  
  122.         @Override  
  123.         public int getItemCount() {  
  124.             return mDataset.length;  
  125.         }  
  126.     }  
  127.       
  128.     static class ViewHolder extends RecyclerView.ViewHolder {  
  129.         // each data item is just a string in this case  
  130.         public TextView mTextView;  
  131.         public ViewHolder(TextView v) {  
  132.             super(v);  
  133.             mTextView = v;  
  134.         }  
  135.     }  
  136. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值