Android Material Design-Getting Started(入门)-(一)

转载请注明出处:http://blog.csdn.net/bbld_/article/details/40400343

翻译自:http://developer.android.com/training/material/get-started.html


要创建materialdesign的app,我们依照例如以下的几个步骤:

1.        回想material design的规范

2.        在app中使用material主题样式

3.        尾随material design准则去创建你的布局

4.        在你的view控件指定elevation(高度,可使控件投影的仰角变化)属性来投射阴影。

5.        使用系统的控件来设计列表和卡片。

6.        在你的app中使用自己定义动画

保持向后兼容

你能够在你的app中加入很多material design的功能特性。同一时候对Android5.0之前的版本号保持兼容。要获得很多其它这方面的信息请參看保持程序的兼性(MaintainingCompatibility)

採用material design更新你的app

要更新现有的app去包括体现material design,(你应该)尾随materialdesign的规范指导去更新你的布局。另外。还要确保结合深入、触摸反馈和动画。

採用material design创建新的app

假设你要通过materialdesign创建一个全新的app,material design的规范指导为你提供了一个紧密结合的设计框架。在Android框架设计和你的应用开发中遵循这些指导并使用新的功能特性。

使用Material主题

在你的app中使用material主题。(你应该)继承指定的主题:android:Theme.Material。

<!-- res/values/styles.xml -->

<resources>

 <!-- your theme inherits from the material theme -->

 <style name="AppTheme" parent="android:Theme.Material">

   <!-- theme customizations -->

 </style>

</resources>


该material主题提供了已经更新的系统控件使得让你能够去设置它们(控件)的调色板和触摸反馈的默认动画和activity的过渡动画效果。获取很多其它的细节。请參看Using the Material Theme  [Android Material Design-Using the Material Theme(使用Material主题)-(二)]

设计你的布局

除了使用或定制material主题,你的布局相同应该符合materialdesign的规范指导。 当你设计布局时。须要特别注意一下几点:

l  基线网格

l  关键的边

l  间隔

l  触摸目标的大小

l  布局结构

在你控件中指定elevation (属性)

控件可以投射阴影,此外elevation属性值决定了一个view控件的影子和它绘制顺序的大小。要设置一个view控件的elevation属性。可以在布局中使用android:elevation属性去设置。

<TextView

   android:id="@+id/my_textview"

   android:layout_width="wrap_content"

   android:layout_height="wrap_content"

   android:text="@string/next"

   android:background="@color/white"

   android:elevation="5dp" />


新的translationZ属性能够让你创建反映在暂时更改view控件levation属性时的动画效果。

Elevation属性改变可能是实用的当响应触摸手势时。

很多其它详情。请參看Defining Shadows and Clipping Views(定义阴影和裁剪视图)

创建列表和卡片(控件)

RecyclerView是一个支持不同的布局类型同一时候提高了显示动态视图性能的增强版ListView。

CardView是一个卡片视图,能够在卡片内显示信息。

能够使用以下的方式创建CardView。

<android.support.v7.widget.CardView

   android:id="@+id/card_view"

   android:layout_width="200dp"

   android:layout_height="200dp"

   card_view:cardCornerRadius="3dp">

   ...

</android.support.v7.widget.CardView>


很多其它的信息,參看Creating Lists and Cards(创建列表和卡片)

自己定义你的动画

Android 5.0(API级别21)包括很多新的API使得你能够在app中去创建自己定义的动画。比如,你能够启用activity的过渡动画和定义activity的退出动画:

public class MyActivity extends Activity {

 

    @Override

   protected void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       // enable transitions

       getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);

       setContentView(R.layout.activity_my);

    }

 

   public void onSomeButtonClicked(View view) {

       getWindow().setExitTransition(new Explode());

       Intent intent = new Intent(this, MyOtherActivity.class);

       startActivity(intent,

                      ActivityOptions

                         .makeSceneTransitionAnimation(this).toBundle());

    }

}


当你从这个activity跳转到还有一个activity时,退出过渡动画是激活的。

要了解很多其它关于新动画的API,请參看Defining Custom Animations(自己定义动画)


原文地址:https://www.cnblogs.com/clnchanpin/p/7056513.html