diff options
Diffstat (limited to 'docs/html/preview/material/ui-widgets.jd')
| -rw-r--r-- | docs/html/preview/material/ui-widgets.jd | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/docs/html/preview/material/ui-widgets.jd b/docs/html/preview/material/ui-widgets.jd index f18bff9..31604d6 100644 --- a/docs/html/preview/material/ui-widgets.jd +++ b/docs/html/preview/material/ui-widgets.jd @@ -14,19 +14,20 @@ page.title=UI Widgets <p>The support library in the Android L Developer Preview contains two new widgets, <code>RecyclerView</code> and <code>CardView</code>. Use these widgets to show complex lists -and cards in your app. These widgets have material design styles and animations by default.</p> +and cards in your app. These widgets have material design style by default.</p> <h2 id="recyclerview">RecyclerView</h2> -<p><code>RecyclerView</code> is a more advanced version of <code>ListView</code>. This widget is -a container for large sets of views that can be recycled and scrolled very efficiently. Use the -<code>RecyclerView</code> widget when you have lists with elements that change dynamically.</p> +<p><code>RecyclerView</code> is a more advanced and flexible version of <code>ListView</code>. +This widget is a container for large sets of views that can be recycled and scrolled very +efficiently. Use the <code>RecyclerView</code> widget when you have lists with elements that +change dynamically.</p> <p><code>RecyclerView</code> is easy to use, because it provides:</p> <ul> - <li>A set of layout managers for positioning items</li> + <li>A layout manager for positioning items</li> <li>Default animations for common item operations</li> </ul> @@ -34,20 +35,9 @@ a container for large sets of views that can be recycled and scrolled very effic widget.</p> <p>To use the <code>RecyclerView</code> widget, you have to specify an adapter and a layout -manager. An <strong>adapter</strong> provides a binding from a dataset to views that are displayed -within a <code>RecyclerView</code>. For example, if your dataset is an array of strings displayed -as <code>TextView</code> items, the layout manager asks the adapter to: -</p> - -<ul> - <li>Set the text of an existing <code>TextView</code> to one of the strings in the dataset</li> - <li>Create new <code>TextView</code> objects</li> - <li>Determine the size of the dataset</li> -</ul> - -<p>To create an adapter, you extend the <code>RecyclerView.Adapter</code> class. The details of -the implementation depend on the specifics of your dataset and the type of views. Fore more -information, see the examples below.</p> +manager. To create an adapter, you extend the <code>RecyclerView.Adapter</code> class. The details +of the implementation depend on the specifics of your dataset and the type of views. For more +information, see the <a href="#rvexamples">examples</a> below.</p> <img src="/preview/material/images/RecyclerView.png" alt="" id="figure1" style="width:550px"/> <p class="img-caption"> @@ -62,16 +52,17 @@ performance by avoiding the creation of unnecessary views or performing expensiv <code>findViewById</code> lookups. </p> -<p><code>RecyclerView</code> provides two layout managers you can use:</p> +<p><code>RecyclerView</code> provides <code>LinearLayoutManager</code>, which shows the items in a +vertical or horizontal scrolling list. To create a custom layout, you extend the +<code>RecyclerView.LayoutManager</code> class.</p> -<ul> - <li><code>LinearLayoutManager</code> shows the items in a vertically scrolling list.</li> - <li><code>GridLayoutManager</code> shows the items in a rectangular grid.</li> -</ul> +<h3>Animations</h3> -<p>To create a custom layout, you extend the <code>RecyclerView.LayoutManager</code> class.</p> +<p>Animations for adding and removing items are enabled by default in <code>RecyclerView</code>. +To customize these animations, extend the <code>RecyclerView.ItemAnimator</code> class and use +the <code>RecyclerView.setItemAnimator</code> method.</p> -<h3>Examples</h3> +<h3 id="rvexamples">Examples</h3> <p>To include a <code>RecyclerView</code> in your layout:</p> @@ -87,7 +78,7 @@ performance by avoiding the creation of unnecessary views or performing expensiv <p>To get the <code>RecyclerView</code> object in your activity:</p> <pre> -public class MyActivity extends ActionBarActivity { +public class MyActivity extends Activity { private RecyclerView mRecyclerView; private RecyclerView.Adapter mAdapter; private RecyclerView.LayoutManager mLayoutManager; @@ -98,7 +89,8 @@ public class MyActivity extends ActionBarActivity { setContentView(R.layout.my_activity); mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); - // improve performance if the size is fixed + // 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 @@ -139,7 +131,8 @@ public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // create a new view - View v = new TextView(parent.getContext()); + 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); @@ -167,22 +160,30 @@ public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { <h2 id="cardview">CardView</h2> <p><code>CardView</code> extends the <code>FrameLayout</code> class and lets you show information -inside a card with optional rounded corners:</p> +inside cards that have a consistent look on any app. <code>CardView</code> widgets can have +shadows and rounded corners.</p> + +<p>To create a card with a shadow, use the <code>android:elevation</code> attribute. +<code>CardView</code> uses real elevation and dynamic shadows +and falls back to a programmatic shadow implementation on earlier versions. For more information, +see <a href="{@docRoot}preview/material/compatibility.html">Compatibility</a>.</p> + +<p>Here's how to specify properties of <code>CardView</code>:</p> <ul> <li>To set the corner radius in your layouts, use the <code>android:cardCornerRadius</code> attribute.</li> <li>To set the corner radius in your code, use the <code>CardView.setRadius</code> method.</li> + <li>To set the background color of a card, use the <code>android:cardBackgroundColor</code> +attribute.</li> </ul> -<p>To set the background color of a card, use the <code>android:cardBackgroundColor</code> -attribute.</p> - <p>To include a <code>CardView</code> in your layout:</p> <pre> <!-- 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" |
