Before starting chapter 5. I hope you have read basic set up ANDROID FOR BEGINNER CHAPTER 2 : INTRODUCTION OF BASIC UI COMPONENTS . Here we will just focus on basic about RecycleView and CardView only.
RecyclerView:-
The
CardView also advance FrameLayout with additional tags like
Layout Manager:-
Download Views :-
To use these 2 component just added following dependency
RecyclerView:-
The
RecyclerView
widget is a more extended and reusable version of ListView
. This widget is very useful to show large data sets that can be scrolled very efficiently by maintaining a limited number of views. Use the RecyclerView
widget instead of ListView for better perfomance.CardView also advance FrameLayout with additional tags like
Layout Manager:-
RecyclerView
provides these built-in layout managers:LinearLayoutManager
shows items in a vertical or horizontal scrolling list.GridLayoutManager
shows items in a grid.StaggeredGridLayoutManager
shows items in a staggered grid.
Examples:-
<!-- 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"/>
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);
// 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
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
// specify an adapter (see also next example)
mAdapter = new MyAdapter(myDataset);
mRecyclerView.setAdapter(mAdapter);
}
...
}
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private String[] mDataset; // Provide a reference to the views for each data item // Complex data items may need more than one view per item, and // you provide access to all the views for a data item in a view holder public static class ViewHolder extends RecyclerView.ViewHolder { // each data item is just a string in this case 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; } }
my_text_view.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
... >
<!-- 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>
</LinearLayout>
CardView :-
It is also extended version of FrameLayout with advanced attributes.
card_view:cardElevation: for creating shadow- To set the corner radius in your layouts, use the card_view:cardCornerRadius attribute.
- To set the corner radius in your code, use the CardView.setRadius method.
- To set the background color of a card, use the card_view:cardBackgroundColor attribute.
Download Views :-
To use these 2 component just added following dependency
dependencies { ... compile 'com.android.support:cardview-v7:21.0.+' compile 'com.android.support:recyclerview-v7:21.0.+'}
1 comments:
Click here for commentsHow To Use Recycleview And Cardview : Chapter 5 ~ Android Lad Ohm >>>>> Download Now
>>>>> Download Full
How To Use Recycleview And Cardview : Chapter 5 ~ Android Lad Ohm >>>>> Download LINK
>>>>> Download Now
How To Use Recycleview And Cardview : Chapter 5 ~ Android Lad Ohm >>>>> Download Full
>>>>> Download LINK
ConversionConversion EmoticonEmoticon