Material Design UI Widgets, materialdesignui

Source: Internet
Author: User

Material Design UI Widgets, materialdesignui


Android L Developer Preview supports two new libraries: Widgets, RecyclerView, and CardView. The two Widgets display the complex Listview and card layout. The two Widgets use Material design by default.


RecyclerView

RecyclerView is a more advanced and flexible version of Listview. RecyclerView is a container that can contain many views. It can perfectly process loops and scrolling. Use RecyclerView In the dynamically changing Listview of item.


RecyclerView is easy to use because it provides:

1. Locate the layout manager of the item

2. Common item operations default Animation


You can flexibly customize layout manager and animation for RecyclerView.

To use RecyclerView, you must specify an adapter and define a layout manager. The created adapter must inherit from RecyclerView. Adapter. The implementation details need to look at the data type and the required view.


RecyclerView widget



RecyclerView provides LayoutManager. RecylerView is not responsible for the layout of sub-views. We can customize LayoutManager to achieve different LayoutManager effects. Currently, only LinearLayoutManager is provided. LinearLayoutManager can specify the direction, which is vertical by default and horizontal. This allows you to easily implement horizontal ListView.


RecyclerView Demo:

1. 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. Activity File

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 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);    }    ...}To create a simple 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, null);        // 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;    }}

3. Recycler 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, null);        // 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;    }}

RecyclerView standardizes ViewHolder. The Adapter is designed for ViewHoder instead of View. The Reusable logic is encapsulated and easier to write.

CardView

CardView inherits from the FrameLayout class and can display consistent content in a card layout. Cards can contain rounded corners and shadows.


You can use the android: elevation attribute to create a shadow card.


How to specify the attributes of CardView:

1. Use the android: cardCornerRadius attribute to specify the radius of the rounded corner.

2. Use CardView. setRadius to set the radius of the rounded corner.

3. Use the android: cardBackgroundColor attribute to set the card color.


Create CardView in the layout file:

<!-- 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>



/*** @ Author Zhang xingye * http://blog.csdn.net/xyz_lmn* my Sina Weibo: @ Zhang xingye TBOW*/


Refer:

Http://developer.android.com/preview/material/ui-widgets.html



JQuery UI widgets IE rounded corner problem for me to implement the ie-css3 of the rounded corner plug-in
Make IE 6, 7, and 8 support some CSS3 attributes
Notes on the official website
Author's official website: http://www.fetchak.com/ie-css3/

Note that you need to deploy a local server to use the server path to enable the running effect.
Double-click to view the effect and an error is returned.

Write for Example

. BorderRadius {border: # E6F2FB 1px solid; background: # fff;-moz-border-radius: 5px;-webkit-border-radius: 5px; border-radius: 5px; position: relative; z-index: 2; behavior: url (js/ie-css3.htc );}

Position: relative; must be effective
JQuery UI widgets-format: function (text). Can text contain html tags? Good meeting

The text format in HTML labels will be interpreted.

Example: <div> test </div>

Text will explain: The full text string <div> tet </div> will be interpreted as "test" and add the DIV format as HTML.

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.