Now if we want a Card type listview and we can simply use RecyclerView with cardview.
CardView is another addon in lolipop which make listing fab.
In order to implement simply follow my Last tutorial for RecyclerView and Add these new Code content there and you are done with CardView.
1. row_recyclerview.xml
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="10dp"
android:layout_margin="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_margin="5dp"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_dark"
android:text="contact det"
android:gravity="center_vertical"
android:textColor="@android:color/white"
android:textSize="14dp"/>
<TextView
android:id="@+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:gravity="center_vertical"
android:textSize="10dp"
android:layout_below="@id/title"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"/>
<TextView
android:id="@+id/txtSurname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Surname"
android:gravity="center_vertical"
android:textSize="10dp"
android:layout_below="@id/txtName"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"/>
<TextView
android:id="@+id/txtEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textSize="10dp"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:layout_marginRight="150dp"
android:layout_alignBaseline="@id/txtName"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
2. RecyclerViewViewHolder.java
public class RecyclerViewViewHolder extends RecyclerView.ViewHolder {
public TextView txtView;
public RecyclerViewViewHolder(View itemView) {
super(itemView);
txtView = (TextView) itemView.findViewById(R.id.title);
}
}
3. RecyclerViewAdapter.java
public class RecyclerViewViewHolder extends RecyclerView.ViewHolder {
public TextView txtView;
public RecyclerViewViewHolder(View itemView) {
super(itemView);
txtView = (TextView) itemView.findViewById(R.id.title);
}
}
4. build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.kamalvaid.recyclerview"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:cardview-v7:21.+'
}
Output :
No comments:
Post a Comment