ANDROID l--material Design Details (UI controls)

Source: Internet
Author: User

Reprint Please indicate this article from Big Corn's blog (http://blog.csdn.net/a396901990 ), thank you for your support!



Android L:


Google has confirmed that Android L is Android Lollipop (5.0).


The previous few days found that the Android5.0 version of the SDK was ready to download, and that the Nexus 6 and Nexus 9, the first to be powered by the Android L system, were also coming soon.

So it's time to start learning Android L!

About Android L How to configure the simulator and create a project, if you are interested, you can look at my previous article:

Android l--Simulator configuration and project creation





Material Design:



Material Design is Google's launch of a The new design language, which is characterized by the flattening of the object.


Material Design contains a lot of content, I roughly divide it into four parts:

Themes and layouts -- ANDROID l--material Design Details (themes and layouts)

views and Shadows- ANDROID l--material Design details (views and shadows)

UI Controls -ANDROID l--material design Details (UI controls)

Animation


Let's talk about the third part today--material new UI Controls




UI Controls
two new controls in Android L were Recyclerview, cardview :

Recyclerview:


Recyclerview is an upgraded version of the ListView that provides better performance and is easier to use.




Recyclerview This control is a large collection of views that can be loaded and can be recycled and scrolled very efficiently. You can use the Recyclerview control when the elements in your list often change dynamically .

The Recyclerview is very easy to use and offers the following two features:

The layout Manager is provided for each entry location ( Recyclerview. Setlayoutmanager )

An action animation is set for each entry ( Recyclerview.setitemanimator )


The following example shows how to define and use a recyclerview:

1. Add a recyclerview to the layout file

<!--A Recyclerview with some commonly used attributes--><android.support.v7.widget.recyclerview    Android : id= "@+id/my_recycler_view"    android:scrollbars= "vertical"    android:layout_width= "Match_parent    " android:layout_height= "Match_parent"/>


2. Initialize the Recyclerview parameter, set LayoutManager and adapter

public class MyActivity extends Activity {    private recyclerview mrecyclerview;    Private Recyclerview.adapter Madapter;    Private Recyclerview.layoutmanager Mlayoutmanager;    @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.my_activity);        Mrecyclerview = (Recyclerview) Findviewbyid (R.id.my_recycler_view);        Improve performance If you know this changes in content//does not change the size of the        recyclerview        mrecycle Rview.sethasfixedsize (true);        Use a linear layout manager        Mlayoutmanager = new Linearlayoutmanager (this);        Mrecyclerview.setlayoutmanager (Mlayoutmanager);        Specify an adapter (see also next example)        Madapter = new Myadapter (myDataSet);        Mrecyclerview.setadapter (Madapter);    }    ...}

3. Create a adapter

public class Myadapter extends recyclerview.adapter<myadapter.viewholder> {private string[] mdataset;  Provide a reference to the type of views the is using//(custom Viewholder) public static class Viewholder        Extends Recyclerview.viewholder {public TextView mtextview;            Public Viewholder (TextView v) {super (V);        Mtextview = v;        }}//provide a suitable constructor (depends on the kind in dataset) public Myadapter (string[] mydataset) {    Mdataset = myDataSet; }//Create new Views (invoked by the layout manager) @Override public Myadapter.viewholder Oncreateviewholder (Vi Ewgroup parent, int viewtype) {//Create a new View view         v = layoutinflater.from (Parent.getcontext ()). Inflate (R.layout.my_text_view, parent, false);  Set the view ' s size, margins, paddings and layout parameters ...      Viewholder VH = new Viewholder (v);    return VH; }//Replace the contents of a view (invoked by the layout manager) @Override public void Onbindviewholder (viewho Lder holder, int position) {//-get element from your dataset at this position//-Replace the contents O    f The view with that element Holder.mTextView.setText (Mdataset[position]);        }//Return the size of your dataset (invoked by the layout manager) @Override public int GetItemCount () {    return mdataset.length; }}


CardView:


CardView inherits from Framelayout, allowing you to display information in the card view. CardView can also set shadows and rounded corners. (In fact, many applications now customize the card view, Google this time the card view as a basic control, can be used directly)





use the CardView to set the fillet in Layout Card_view:cardcornerradius Properties

Use the Cardview.setradius method to set rounded corners for CardView in your code

to be CardView Setting the background color using the card_view:cardbackgroundcolor Property


Include a CardViewin the layout, as follows:

<!--a cardview that contains a TextView--><android.support.v7.widget.cardview    xmlns:card_view= "/http Schemas.android.com/apk/res-auto "    android:id=" @+id/card_view "    android:layout_gravity=" center    " Android:layout_width= "200DP"    android:layout_height= "200DP"    card_view:cardcornerradius= "4DP" >    <textview        android:id= "@+id/info_text"        android:layout_width= "match_parent"        android:layout_height = "Match_parent"/></android.support.v7.widget.cardview>

Compatibility:
recyclerview,cardview are included in the Android L Developer Preview support Library , So they can be used in previous versions and there are only a few limitations.



Summarize:


I divide material design into the following four parts:

Themes and layouts -- ANDROID l--material Design Details (themes and layouts)

views and Shadows- ANDROID l--material Design details (views and shadows)

UI Controls -- ANDROID l--material Design Details (UI controls)

Animation


The two controls (Recyclerview,cardview) described in this article are important because they are often used in future development of the Android L.


This article is about the translation from the official documents, you may be a little confused. But it doesn't matter, in a few days I will update an introduction to Recyclerview,CardView in Android studio and Eclipse is how to guide the package, and two controls in combination with 's Little demo.


Material Desgin The introduction of only the animation part , I will update as soon as possible, please look forward to ...



ANDROID l--material Design Details (UI controls)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.