6. RecyclerView
The RecyclerView widget is a more advanced and flexible
version of ListView. This widget is a container for displaying
large data sets that can be scrolled very efficiently by
maintaining a limited number of views. Use the Recycler
View widget when you have data collections whose elements
change at runtime based on user action or network events.
@MhmdAljobairi
7. <!-- 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"/>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
// use a linear layout manager
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
// specify an adapter (see also next example)
RecyclerView.Adapter mAdapter = new MyAdapter(myDataset);
mRecyclerView.setAdapter(mAdapter);
}
@MhmdAljobairi
8. Cards
Usage
● Cards are a convenient means of displaying content
composed of different types of objects
● A card collection is a coplanar layout of cards.
● Each of these cards contains a unique data set
● a checklist with an action, a note with an action, a
note with a photo.
@MhmdAljobairi
10. Z value
The Z value for a view has two components, elevation and translation. The elevation is the static component, and the translation is
used for animations:
Z = elevation + translationZ
To set the elevation of a view:
● In a layout definition, use the android:elevation attribute.
● In the code of an activity, use the View.setElevation method.
@MhmdAljobairi
11. Consider this view, defined with a background drawable:
<TextView
android:id="@+id/myview"
...
android:elevation="2dp"
android:background="@drawable/myrect" />
The background drawable is defined as a rectangle with rounded corners:
<!-- res/drawable/myrect.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#42000000" />
<corners android:radius="5dp" />
</shape>
@MhmdAljobairi
31. View myView = findViewById(R.id.my_view);
// get the center for the clipping circle
int cx = (myView.getLeft() + myView.getRight()) / 2;
int cy = (myView.getTop() + myView.getBottom()) / 2;
// get the final radius for the clipping circle
int finalRadius = Math.max(myView.getWidth(), myView.getHeight());
// create the animator for this view (the start radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
myView.setVisibility(View.VISIBLE);
anim.start();