Android5.0 (Lollipop) Introduction of new Features (I.)

Source: Internet
Author: User
Tags recyclerview android

At the Google I/O conference this June, I believe that the first meeting of Android L will let a lot of Android fans have some small excitement and small expectations, of course, as the developer of me, the excitement is self-evident, after all, this is the biggest change since 08. The new design language (Material), more than 5,000 new APIs. Needless to say, the basic of today's talk is very common in Android5.0, but also a record of their own learning.

1.CardView

As the name implies, the CardView card view, inherited from the Framelayout, can be displayed with the same effect as a card by setting fillets and shadows



Usage: in Layout declaration CardView (Note: need to introduce Android-support-v7-cardview.jar)

<span Style= "FONT-SIZE:14PX;" ><android.support.v7.widget.cardview android:id= "@+id/cardview" android:layout_width= "Fill_par Ent "android:layout_height=" wrap_content "android:elevation=" 100DP "Card_view:cardbackgro Undcolor= "@color/cardview_initial_background" card_view:cardcornerradius= "8DP" Android:layout_margin                left= "@dimen/margin_large" android:layout_marginright= "@dimen/margin_large" > <textview Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:lay out_margin= "@dimen/margin_medium" android:text= "@string/cardview_contents"/></ANDROID.SUPPORT.V7.WIDG Et. Cardview></span> 
in activity, you set the fillet and shadow of the CardView by calling Mcardview.setradius (progress) and mcardview.setelevation (progress) methods respectively.


2.RecyclerView


The advent of Recyclerview can replace the ListView and the GridView, which standardizes the viewholder before we need to customize Viewholder to improve the ListView speed when writing the adapter of the ListView. When using Recyclerview, it is necessary to set LayoutManager, which informs the system what layout to display Recyclerview, the system now provides 2 kinds of layoutmanager, Linearlayoutmanager and Gridlayoutmanager correspond to linear and lattice, and of course can be customized layoutmanager to meet a variety of needs

Usage: Declare recyclerview in Layout file (note: need to introduce 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:lay Out_width= "Match_parent" android:layout_height= "wrap_content" android:gravity= "Center_horizontal" and roid: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/gri D_layout_manager "/> </RadioGroup> <android.support.v7.widget.recyclerview android:id=" @+id/recycl ErVIew "android:layout_width=" match_parent "android:layout_height=" Match_parent "/></linearlayout></ Span>


Call the following code in the activity

<span style= "FONT-SIZE:14PX;" >mrecyclerview = (Recyclerview) Rootview.findviewbyid (R.id.recyclerview);// Similar to Listviewmrecyclerview.setlayoutmanager (New Linearlayoutmanager (Getactivity ()));// Similar to Grdiviewmrecyclerview.setlayoutmanager (New Gridlayoutmanager (Getactivity (), 3)) Madapter = new Customadapter ( Mdataset);//Set Customadapter as the adapter for RecyclerView.mRecyclerView.setAdapter (madapter);</span>

The Customadapter code is as follows

<span style= "FONT-SIZE:14PX;" >public class Customadapter extends recyclerview.adapter<customadapter.viewholder> {private static final Stri    ng TAG = "Customadapter";    Private string[] Mdataset; /** * Provide a reference to the type of views that is using (custom viewholder) */public static class Vi        Ewholder 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-used by RECYCLErview.    */Public Customadapter (string[] DataSet) {mdataset = DataSet; }//Create new Views (invoked by the layout manager) @Override public viewholder Oncreateviewholder (ViewGroup VI        Ewgroup, 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 (viewho Lder Viewholder, Final int position) {//Get element from your datasets at this position and replace the contents O        f 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&Gt 

Introduced here today, the follow-up will also introduce Floatactionbar, touch feedback, activity scenes animation and so on.

Reproduced please mark the source, thank you ~


Android5.0 (Lollipop) Introduction of new Features (I.)

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.