Android l-Material Design (UI control) and androidui

Source: Internet
Author: User

Android l-Material Design (UI control) and androidui

Reprinted please indicate this article from the blog of the big glutinous rice ( Thank you for your support!

Android L:

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

A few days ago, we found that the official version of Android sdk can be downloaded, and the first Nexus 6 and Nexus 9 equipped with the Android L system will be available soon.

So it's time to start learning Android L!

For more information about how to configure simulators and create projects for Android L, see my previous article:

Android L-Simulator configuration and Project Creation

Material Design:

Material DesignIt is a brand new design language launched by Google. It features flat objects.

Material DesignIt contains a lot of content, which is roughly divided into four parts:

Themes and Layout--Android l-Material Design (subject and layout)

View and shadow-android l-Material Design (view and shadow)

UI control--Android l -- Material Design (UI control)


Let's talk about the third part today --New UI control of Material

UI control
Two new controls are added in Android L: RecyclerView, CardView:


RecyclerView is an upgraded version of ListView, which provides better performance and is easier to use.

RecyclerView is a control that can load a large number of View sets and can be efficiently recycled and rolled. You can use the RecyclerView control when the elements in your list frequently change dynamically.

RecyclerView is very easy to use. It provides the following two functions:

The layout manager (RecyclerView. setLayoutManager)

An operation animation (RecyclerView. setItemAnimator)

The following example describes how to define and use RecyclerView:

1. Add a RecyclerView to the layout file.

<!-- A RecyclerView with some commonly used attributes --><    android:id="@+id/my_recycler_view"    android:scrollbars="vertical"    android:layout_width="match_parent"    android:layout_height="match_parent"/>

2. initialize the RecyclerView parameter and 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(;        // improve performance if you know that changes in content        // do not change the size of the RecyclerView        mRecyclerView.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 an adapter

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {    private String[] mDataset;    // Provide a reference to the type of views that you are 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 of dataset)    public MyAdapter(String[] myDataset) {        mDataset = myDataset;    }    // Create new views (invoked by the layout manager)    @Override    public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup 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(ViewHolder holder, int position) {        // - get element from your dataset at this position        // - replace the contents of 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 inherits from FrameLayout, allowing you to display information in the card view. CardView can also set shadows and rounded corners. (In fact, many applications have customized the Card view. Google uses the card view as the basic control and can use it directly)

Set rounded corner for CardView in LayoutCard_view: cardCornerRadiusAttribute

Set the rounded corner for CardView in the code.CardView. setRadiusMethod

Set background color for CardViewCard_view: cardBackgroundColorAttribute

The layout contains a CardView, as shown below:

<!-- A CardView that contains a TextView --><    xmlns:card_view=""    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" /></>

RecyclerView and CardView are all included in the Android L Developer Preview Support Library, so they can be used in earlier versions with only some restrictions.


Material Design is divided into the following four parts:

Themes and Layout--Android l-Material Design (subject and layout)

View and shadow-android l-Material Design (view and shadow)

UI control--Android l -- Material Design (UI control)


The two controls described in this article (RecyclerView, CardView) are very important because they will be frequently used in future Android L development.

The content introduced in this article is translated from official documents, which may be a bit confusing. But it doesn't matter. In a few days, I will update an introduction to RecyclerView. How does CardView export packages in Android Studio and Eclipse and a small Demo used in combination with the two controls.

Only the introduction of Material Desgin is leftAnimationPartially,I will update it as soon as possible, so stay tuned...

I am an Android beginner. What does Android l mean for beginners?

It doesn't mean anything. Beginners need to learn the latest. The major changes of Android L are mainly reflected in the UI and functions. Google proposed the Design concept of Material Design. I think the code structure of this version is basically no different from that of the previous Android version, so most documents can still be used. We recommend that you download an Android L development document from Google to see if there are any changes in the Code. Because you are a beginner, it is recommended that you give priority to card layout and Fragment during design, and do not use methods and classes discarded after Android 2.3. I am also an Android developer and have made some small applications. If you have any questions, please feel free to ask. I hope this will help you.

Saying that G2 has the opportunity to be flushed into android L?

Today, Android L is installed on Nexus 7. It is really worth looking forward to, but there are still a lot of incompatible software .. But the smoothness is true .. It is worth looking forward .. View Original post>

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: 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.