How to use RecyclerView with multiple cardView layouts in Android Example 

  • Codeplayon
  • May 5, 2020
  • Comments Off on How to use RecyclerView with multiple cardView layouts in Android Example 

Hii everyone in this topic we have a discussion on recyclerView with multiple card layout. Today latest android UI  market you can see most of the App has used multiple card layout like e-commerce Apps, Social media Apps, most use multiple UI.Card layout in your ListView. like Full-screen card UI, Overlay text, Image card. How to use RecyclerView with multiple cardView layouts in Android Example.

So in the Android tutorial, I implement A array list response with Rest API response in recyclerView list With Multiple Card layout. I’m adapter class we have control  UI and Show a travel list data with multiple card layout.

Let’s Start on topic How to use RecyclerView with multiple cardView layouts in Android Example.

first of creating your Android project with the latest Android SDK API level 29 and using AndroidX and add this dependency.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "androidx.drawerlayout:drawerlayout:1.0.0"
    implementation 'com.google.android.material:material:1.1.0'
    implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'de.hdodenhof:circleimageview:2.1.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'

Step 1: Main activity Layout file Souce code.

in your main activity layout file, you can add a recycler view layout and implement it in your java class.

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/Home_RecyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_marginBottom="23dp"/>

 

Step 2: Your main activity java class add this code. 

in your java file, you can get a response for rest API using Volley and using JSON parser your can pars your API response in your adapter class and implement recycler view. here I am using an Android fragment.

public class Home_Tab extends Fragment {

    private RecyclerView firstRecyclerView;
    private HomeAdupter rAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_home__tab, container,
                false);
       
        firstRecyclerView = (RecyclerView) rootView.findViewById(R.id.Home_RecyclerView);
        firstRecyclerView.setHasFixedSize(true);
       
        HomeDetails();
         
        // Do something else
        return rootView;
    }
// Get Request For JSONObject
public void HomeDetails(){
    final ProgressDialog loading = new ProgressDialog(getActivity());
    loading.setMessage("Please Wait...");
    loading.setCanceledOnTouchOutside(false);
    loading.show();
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, ConfiURL.Home_Screen_URL, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            Log.d("Response", response.toString());

            try {
                Log.d("JSON", String.valueOf(response));
                loading.dismiss();
                String Error = response.getString("httpStatus");
                if(Error.equals("OK")){
                    JSONObject Body = response.getJSONObject("body");
                    JSONArray list = Body.getJSONArray("list");
                    onPostbanners(banners);
                    onPostlist(list);

                }else if(Error.equals("")||Error.equals(null)){

                }else {

                }

            } catch (JSONException e) {
                e.printStackTrace();
                loading.dismiss();

            }

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            loading.dismiss();
            VolleyLog.d("Error", "Error: " + error.getMessage());
            if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                ContextThemeWrapper ctw = new ContextThemeWrapper( getActivity(), R.style.Theme_AlertDialog);
                final android.app.AlertDialog.Builder alertDialogBuilder = new android.app.AlertDialog.Builder(ctw);
                alertDialogBuilder.setTitle("No connection");
                alertDialogBuilder.setMessage(" Connection time out error please try again ");
                alertDialogBuilder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                    }
                });
                alertDialogBuilder.show();
         
            }
        }
    })
    {
        @Override
        public String getBodyContentType() {
            return "application/json; charset=utf-8";
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Authorization", ConfiURL.Token);
            return headers;
        }
    };
    RequestQueue queue = Volley.newRequestQueue(getActivity());
    queue.add(req);
}
 protected void onPostlist(JSONArray result) {
        //this method will be running on UI thread
        List<DataObject> data = new ArrayList<>();
        data.equals(null);
        try {
            // Extract data from json and store into ArrayList as class objects
            for (int i = 0; i < result.length(); i++) {
                JSONObject json_data = result.getJSONObject(i);
                DataObject report = new DataObject();
                report.mText1 = json_data.getString("id");
                report.mText2 = json_data.getString("title");
                report.mText3 = json_data.getString("topic");
                report.mText4 = json_data.getString("description");
                report.mText5 = json_data.getString("location");
                report.mText6 = json_data.getString("type");
                report.categoryName = json_data.getString("categoryName");
                report.mText8 = json_data.getString("personName");
                report.mText9 = json_data.getString("companyImageUrl");
                report.mText10 = json_data.getString("date");
                report.Image = json_data.getString("thumbnailImageUrl");
                data.add(report);
            }

            rAdapter = new HomeAdupter(getActivity(), data);
            firstRecyclerView.setAdapter(rAdapter);
            GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),1);
            firstRecyclerView.setLayoutManager(gridLayoutManager);


        } catch (JSONException e) {
            Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_LONG).show();
        }
    }

Step 3:  Recyclerview List Adapter Class Source Code.

In your Adapter, class you can Create multiple View Holder and control every view holder to a different card layout according  to the Status base  and Create multiple layout card according to your UI and add your layout According to status

public class HomeAdupter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Activity context;
    private LayoutInflater inflater;
    List<DataObject> data = Collections.emptyList();

    private static final int TYPE_EVENT = 1;
    private static final int TYPE_VIDEOS = 2;
    private static final int TYPE_ARTICLES = 3;
    private static final int TYPE_CASESTUDY = 4;
    private static final int TYPE_BLOGS = 5;
    private static final int TYPE_TESTIMONIALS = 6;
    private static final int TYPE_DEFAULT = 7;
    String Link;
    String userImage;
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    public HomeAdupter(Activity context, List<DataObject> data) {
        this.context = context;
        // inflater = LayoutInflater.from(context);
        this.data = data;
    }

    @Override
    public int getItemViewType(int position) {
        DataObject dataObject = data.get(position);
        String status = dataObject.getmText6();
        if (status.equalsIgnoreCase("event")) {
            return TYPE_EVENT;
        } else if (status.equalsIgnoreCase("videos")) {
            return TYPE_VIDEOS;
        } else if (status.equalsIgnoreCase("articles")) {
            return TYPE_ARTICLES;
        } else if (status.equalsIgnoreCase("case studies")){
            return TYPE_CASESTUDY;
        } else if (status.equalsIgnoreCase("blogs")) {
            return TYPE_BLOGS;
        }else if (status.equalsIgnoreCase("testimonials") ) {
            return TYPE_TESTIMONIALS;
        } else {
            return TYPE_DEFAULT;
        }
    }

    // Inflate the layout when viewholder created
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == TYPE_EVENT) {
            View view = inflater.from(parent.getContext()).
                    inflate(R.layout.item_layout_event, parent, false);
            return new EventViewHolder(view);
        } else if (viewType == TYPE_ARTICLES) {
            View view = inflater.from(parent.getContext()).
                    inflate(R.layout.item_layout_articles, parent, false);
            return new ArticleViewHolder(view);
        } else if (viewType == TYPE_CASESTUDY) {
            View view = inflater.from(parent.getContext()).
                    inflate(R.layout.item_layout_casestudy, parent, false);
            return new CaseStudyViewHolder(view);
        } else if (viewType == TYPE_VIDEOS) {
            View view = inflater.from(parent.getContext()).
                    inflate(R.layout.item_layout_videos, parent, false);
            return new VideoViewHolder(view);
        }else if (viewType == TYPE_BLOGS) {
            View view = inflater.from(parent.getContext()).
                    inflate(R.layout.item_layout_blog, parent, false);
            return new BlogViewHolder(view);
        }else if (viewType == TYPE_TESTIMONIALS) {
            View view = inflater.from(parent.getContext()).
                    inflate(R.layout.item_layout_testimonials, parent, false);
            return new TestimonialsViewHolder(view);
        }else if (viewType == TYPE_DEFAULT) {
            View view = inflater.from(parent.getContext()).
                    inflate(R.layout.item_layout_home_default, parent, false);
            return new DefaultViewHolder(view);
        }else {
            throw new RuntimeException("The type has to be EVENT or ARTICLES or VIDEOS or CASE STUDY");
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        switch (holder.getItemViewType()) {
            case TYPE_EVENT:
                initLayoutEvent((EventViewHolder) holder, position);
                break;
            case TYPE_ARTICLES:
                initLayoutArticle((ArticleViewHolder) holder, position);
                break;
            case TYPE_CASESTUDY:
                initLayoutCaseStudy((CaseStudyViewHolder) holder, position);
                break;
            case TYPE_VIDEOS:
                initLayoutVideo((VideoViewHolder) holder, position);
                break;
            case TYPE_BLOGS:
                initLayoutBlog((BlogViewHolder) holder, position);
                break;
            case TYPE_TESTIMONIALS:
                initLayoutTestimonials((TestimonialsViewHolder) holder, position);
                break;
            case TYPE_DEFAULT:
                initLayoutDefault((DefaultViewHolder) holder, position);
                break;
            default:
                break;
        }
    }


    @Override
    public int getItemCount() {
        return data.size();
    }

    private void initLayoutEvent(EventViewHolder holder, int pos) {
        DataObject current = data.get(pos);
        holder.tvEventTitle.setText(current.getCategoryName());
        holder.tvEventDescription.setText(current.getmText2());
        userImage = current.getImage();
        if (userImage.isEmpty()) {

        } else {
            Picasso.with(context)
                    .load(userImage)
                    .placeholder(R.drawable.app_icons)
                    .into((holder).ivEventImage);
        }
    }

    private void initLayoutBlog(BlogViewHolder holder, int pos) {
        DataObject current = data.get(pos);
        holder.tvBlogHeader.setText(current.getmText2());
        holder.tvBlogFooter.setText(current.getmText4());
        userImage = current.getImage();
        if (userImage.isEmpty()) {

        } else {
            Picasso.with(context)
                    .load(userImage)
                    .placeholder(R.drawable.app_icons)
                    .into((holder).ivBlogImage);
        }
    }

    private void initLayoutVideo(VideoViewHolder holder, int pos) {
        DataObject current = data.get(pos);
        holder.tvVideoTitle.setText(current.getmText2());
        holder.tvVideoDescription.setText(current.getmText4());

        userImage = current.getImage();
        if (userImage.isEmpty()) {

        } else {
            Picasso.with(context)
                    .load(userImage)
                    .placeholder(R.drawable.app_icons)
                    .into((holder).ivVideoImage);
        }
    }

    private void initLayoutArticle(ArticleViewHolder holder, int pos) {
        DataObject current = data.get(pos);
//        holder.tvEventCategory.setText(current.getCategoryName());
        holder.tvArticleTitle.setText(current.getmText2());
        userImage = current.getImage();
        if (userImage.isEmpty()) {

        } else {
            Picasso.with(context)
                    .load(userImage)
                    .placeholder(R.drawable.app_icons)
                    .into((holder).ivArticleImage);
        }
    }

    private void initLayoutCaseStudy(CaseStudyViewHolder holder, int pos) {
        DataObject current = data.get(pos);
        holder.tvCaseStudyTitle.setText(current.getmText2());
    }

    private void initLayoutTestimonials(TestimonialsViewHolder holder, int pos) {
        DataObject current = data.get(pos);
//        holder.tvEventCategory.setText(current.getCategoryName());
        holder.tvTestimonialDesc.setText(current.getmText4());
        holder.tvTestimonialUserName.setText(current.getmText2());
        holder.tvTestimonialUserDesignation.setText(current.getmText4());
        userImage = current.getImage();
        if (userImage.isEmpty()) {

        } else {
            Picasso.with(context)
                    .load(userImage)
                    .placeholder(R.drawable.app_icons)
                    .into((holder).ivTestimonialsUserImage);
        }
    }


    private void initLayoutDefault(DefaultViewHolder holder, int pos) {
        DataObject current = data.get(pos);
//        holder.tvEventCategory.setText(current.getCategoryName());
        holder.tvDefaultCardTitle.setText(current.getmText6());
//        holder.tvDefaultCategory.setText(current.getmText2());
        holder.tvDefaultDescription.setText(current.getmText2());
        userImage = current.getImage();
        if (userImage.isEmpty()) {

        } else {
            Picasso.with(context)
                    .load(userImage)
                    .placeholder(R.drawable.app_icons)
                    .into((holder).ivDefaultImage);
        }
    }


    class MyHolder extends RecyclerView.ViewHolder {

        TextView CardArticle_Name, CardArticle_Des, CardArticle_PostON, CardArticle_Id;
        ImageView CardArticle_image, Home_Event_image;
        Button View_CardArticle, Downlod_Article;
        CardView home_event_card;
        TextView Home_EventName, Home_EventDate, Home_EventMonth, Home_Event_Title;

        // create constructor to get widget reference
        public MyHolder(View itemView) {
            super(itemView);
            home_event_card = (CardView) itemView.findViewById(R.id.home_event_card);
            Home_EventName = (TextView) itemView.findViewById(R.id.Home_EventName);
            Home_EventDate = (TextView) itemView.findViewById(R.id.Home_EventDate);
            Home_EventMonth = (TextView) itemView.findViewById(R.id.Home_EventMonth);
            Home_Event_Title = (TextView) itemView.findViewById(R.id.Home_Event_Title);
            Home_Event_image = (ImageView) itemView.findViewById(R.id.Home_Event_image);
        }

    }

    // Static inner class to initialize the views of rows
    static class EventViewHolder extends RecyclerView.ViewHolder {
        TextView tvEventDescription, tvEventTitle;
        ImageView ivEventImage;
        TextView viewAllButton;

        public EventViewHolder(View itemView) {
            super(itemView);
            tvEventDescription = itemView.findViewById(R.id.eventDescription);
            tvEventTitle = itemView.findViewById(R.id.eventTitle);
            ivEventImage = itemView.findViewById(R.id.eventImage);
            viewAllButton = itemView.findViewById(R.id.eventViewAllButton);
        }
    }

    // Static inner class to initialize the views of rows
    static class TestimonialsViewHolder extends RecyclerView.ViewHolder {
        TextView tvTestimonialDesc,tvTestimonialUserName,tvTestimonialUserDesignation;
        ImageView ivTestimonialsUserImage;
        TextView viewAllButton;

        public TestimonialsViewHolder(View itemView) {
            super(itemView);
            tvTestimonialDesc = itemView.findViewById(R.id.testimonialDescription);
            ivTestimonialsUserImage = itemView.findViewById(R.id.testimonialsUserImage);
            viewAllButton = itemView.findViewById(R.id.eventViewAllButton);
            tvTestimonialUserName = itemView.findViewById(R.id.testimonialUserName);
            tvTestimonialUserDesignation = itemView.findViewById(R.id.testimonialUserDesignation);
        }
    }

    // Static inner class to initialize the views of rows
    static class DefaultViewHolder extends RecyclerView.ViewHolder {
        TextView tvDefaultCardTitle,tvDefaultCategory,tvDefaultDescription;
        ImageView ivDefaultImage;
        TextView viewAllButton;

        public DefaultViewHolder(View itemView) {
            super(itemView);
            tvDefaultCardTitle = itemView.findViewById(R.id.defaultCardViewTitle);
            ivDefaultImage = itemView.findViewById(R.id.defaultImage);
            viewAllButton = itemView.findViewById(R.id.eventViewAllButton);
            tvDefaultCategory = itemView.findViewById(R.id.defaultCategory);
            tvDefaultDescription = itemView.findViewById(R.id.defaultDescription);
        }
    }

    static class VideoViewHolder extends RecyclerView.ViewHolder {
        TextView  tvVideoTitle;
        ImageView ivVideoImage;
        TextView viewAllButton;
        TextView tvVideoDescription;

        public VideoViewHolder(View itemView) {
            super(itemView);
            tvVideoTitle = itemView.findViewById(R.id.videoTitle);
            ivVideoImage = itemView.findViewById(R.id.videoImage);
            viewAllButton = itemView.findViewById(R.id.videosViewAll);
            tvVideoDescription = itemView.findViewById(R.id.videoDescription);
        }
    }

    // Static inner class to initialize the views of rows
    static class ArticleViewHolder extends RecyclerView.ViewHolder {
        TextView  tvArticleCategory,tvArticleTitle;
        ImageView ivArticleImage;
        TextView viewAllButton;

        public ArticleViewHolder(View itemView) {
            super(itemView);
            tvArticleTitle = itemView.findViewById(R.id.articleDescription);
            ivArticleImage = itemView.findViewById(R.id.articleImage);
            viewAllButton = itemView.findViewById(R.id.articleViewAll);
        }
    }

    // Static inner class to initialize the views of rows
    static class BlogViewHolder extends RecyclerView.ViewHolder {
        TextView  tvBlogHeader,tvBlogFooter;
        ImageView ivBlogImage;
        TextView viewAllButton;

        public BlogViewHolder(View itemView) {
            super(itemView);
            tvBlogHeader = itemView.findViewById(R.id.blogHeader);
            ivBlogImage = itemView.findViewById(R.id.blogImage);
            viewAllButton = itemView.findViewById(R.id.articleViewAll);
            tvBlogFooter = itemView.findViewById(R.id.blogFooter);
        }
    }

    static class CaseStudyViewHolder extends RecyclerView.ViewHolder {
        TextView  tvCaseStudyTitle;
        TextView viewAllButton;

        public CaseStudyViewHolder(View itemView) {
            super(itemView);
            tvCaseStudyTitle = itemView.findViewById(R.id.caseStudyDesc);
            viewAllButton = itemView.findViewById(R.id.caseStudyViewAll);
        }
    }

}

Step 4 Data Object getter Setter  Class Souce code.

public class DataObject {
    public String mText1;
    public String mText2;
    public String mText3;
    public String mText4;
    public String mText5;
    public String mText6;
    public String mText7;
    public String categoryName;
    public String mText8;
    public  String mText9;
    public  String mText10;
    public String Image;
    public String Image1;
    private boolean isSelected;

    public String getImage() {
        return Image;
    }

    public void setImage(String image) {
        Image = image;
    }

    public String getImage1() {
        return Image1;
    }

    public void setImage1(String image) {
        Image1 = image;
    }

    public String getmText1() {
        return mText1;
    }

    public void setmText1(String mText1) {
        this.mText1 = mText1;
    }

    public String getmText2() {
        return mText2;
    }

    public void setmText2(String mText2) {
        this.mText2 = mText2;
    }

    public String getmText3() {
        return mText3;
    }

    public void setmText3(String mText3) {
        this.mText3 = mText3;
    }

    public String getmText4() {
        return mText4;
    }

    public void setmText4(String mText4) {
        this.mText4 = mText4;
    }

    public String getmText5() {
        return mText5;
    }

    public void setmText5(String mText5) {
        this.mText5 = mText5;
    }
    public String getmText6() {
        return mText6;
    }

    public void setmText6(String mText6) {
        this.mText6 = mText6;
    }

    public String getmText7() {
        return mText7;
    }

    public void setmText7(String mText7) {
        this.mText7 = mText7;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }
    
}

1.  Card Layout Souce Code item_article.xml  Layout Souce code.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/Home_Article_CardView"
    android:layout_margin="10dp"
    android:elevation="5dp"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView
        android:id="@+id/Home_Article_image"
        android:layout_width="match_parent"
        android:background="@drawable/articles"
        android:layout_height="250dp" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:padding="5dp"
        android:gravity="center"
        android:layout_alignParentTop="true"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/Home_Article"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:textColor="@color/White"
            android:layout_weight="1"
            android:elevation="5dp"
            android:textAppearance="@style/page_title"
            android:text="Articles"/>

        <TextView
            android:id="@+id/View_ArticleBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:textColor="@color/White"
            android:elevation="5dp"
            android:gravity="right"
            android:textAppearance="@style/small_indic"
            android:text="@string/view_all"/>
    </LinearLayout>

    <TextView
        android:id="@+id/Home_Article_Des"
        android:textColor="@color/White"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textMultiLine"
        android:layout_margin="30dp"
        android:textStyle="bold"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:textAppearance="@style/body"
        android:elevation="5dp"
        android:padding="15dp"
        android:text="This is a  latest Events you can see share" />

</RelativeLayout>

 

2. Blog card layout file source code.

 

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/Home_Blog_Card"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="10dp"
    app:cardBackgroundColor="@color/White"
    app:cardCornerRadius="2dp"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <TextView
            android:id="@+id/Home_Blog_Title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="@style/page_title"
            android:textStyle="bold"
            android:gravity="left"
            android:elevation="5dp"
            android:padding="15dp"
            android:text="Top 5 Managed Security Trends Watch Out in 2020 " />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="5dp">
            <ImageView
                android:id="@+id/Home_Blog_image"
                android:layout_width="match_parent"
                android:background="@drawable/blog"
                android:layout_height="220dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:layout_alignTop="@+id/Home_Blog_image"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/Home_Blogs"
                    android:layout_width="match_parent"
                    android:layout_height="46dp"
                    android:layout_weight="1"
                    android:textColor="@color/White"
                    android:padding="5dp"
                    android:text="Blogs"
                    android:textAppearance="@style/page_title"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/View_BlogBtn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:textColor="@color/White"
                    android:gravity="right"
                    android:textAppearance="@style/small_indic"
                    android:text="@string/view_all"/>
            </LinearLayout>

        </RelativeLayout>
        <TextView
            android:id="@+id/Home_Blog_Des"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="@style/body"
            android:textStyle="bold"
            android:elevation="5dp"
            android:padding="15dp"
            android:text="This is a  latest news you can see share" />
    </LinearLayout>
</androidx.cardview.widget.CardView>

3. Video card layout Souce Code.

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/Home_Video_Layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageView
        android:id="@+id/Home_Video_Image"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:background="@drawable/video"
        android:contentDescription="@null" />

    <ImageView
        android:id="@+id/Home_PlayVideo"
        android:layout_width="60dp"
        android:layout_height="60sp"
        android:tint="@color/White"
        android:src="@drawable/baseline_play_circle_filled_24"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"/>

    <LinearLayout
        android:id="@+id/Video_LinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:layout_alignTop="@+id/Home_PlayVideo"
        android:layout_alignParentTop="true"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/Home_Video"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:textColor="@color/White"
                android:layout_weight="1"
                android:elevation="5dp"
                android:textAppearance="@style/page_title"
                android:text="Videos"/>

            <TextView
                android:id="@+id/View_VideoBtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:textColor="@color/White"
                android:elevation="5dp"
                android:gravity="right"
                android:textAppearance="@style/small_indic"
                android:text="@string/view_all"/>

        </LinearLayout>

        <TextView
            android:id="@+id/Home_Video_Title"
            android:textColor="@color/White"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="@style/page_title"
            android:elevation="5dp"
            android:padding="5dp"
            android:text="Cloud Technology" />
    </LinearLayout>



    <TextView
        android:id="@+id/Home_Video_Des"
        android:textColor="@color/White"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:inputType="textMultiLine"
        android:textAppearance="@style/body"
        android:layout_alignParentBottom="true"
        android:textStyle="bold"
        android:elevation="5dp"
        android:padding="15dp"
        android:text="This is a  latest Events you can see share" />
</RelativeLayout>

4.  Testimonial Card layout Souce Code.

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/Home_Testimonials_Card"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="10dp"
    app:cardBackgroundColor="@color/White"
    app:cardCornerRadius="2dp"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/Home_Testimonials"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:padding="5dp"
                android:text="Testimonials"
                android:textAppearance="@style/page_title"
                android:textColor="@color/Gray2"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/View_TestiBtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:gravity="center"
                android:textAppearance="@style/small_indic"
                android:text="@string/view_all"/>
        </LinearLayout>

        <ImageView
            android:layout_width="wrap_content"
            android:src="@drawable/qutations"
            android:layout_marginLeft="15dp"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/Testimonial_Des"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="@style/body"
            android:inputType="textMultiLine"
            android:maxLines="4"
            android:elevation="5dp"
            android:padding="15dp"
            android:text="This is a  latest news you can see share This is a  latest news you can see share This is a  latest news you can see share This is a  latest news you can see share This is a  latest news you can see share This is a  latest news you can see share " />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="25dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:layout_marginRight="25dp"
            android:background="@color/Gray4" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginBottom="15dp"
            android:orientation="horizontal">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/VisitImage"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_gravity="center"
                android:src="@drawable/baseline_person_24"
                app:civ_border_color="@color/Gray4"
                app:civ_border_width="2dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:layout_gravity="center"
                android:gravity="center"
                android:orientation="vertical">


                <TextView
                    android:id="@+id/TestiName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAppearance="@style/position"
                    android:text="ABCD XYZ"/>


                <TextView
                    android:id="@+id/Testi_Postion"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="@color/Gray2"
                    android:textAppearance="@style/small_indic"
                    android:text="VP testing"/>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</androidx.cardview.widget.CardView>

 

5.  whitepaper Card View layout screen Souce code.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="5dp"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView
        android:id="@+id/Home_WhaitePaper_image"
        android:layout_width="match_parent"
        android:background="@drawable/white_paper"
        android:layout_height="250dp" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:padding="5dp"
        android:gravity="center"
        android:layout_alignParentTop="true"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/Home_Paper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:textColor="@color/White"
            android:layout_weight="1"
            android:elevation="5dp"
            android:textAppearance="@style/page_title"
            android:text="Whitepapers"/>

        <TextView
            android:id="@+id/View_PaperBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:textColor="@color/White"
            android:elevation="5dp"
            android:gravity="right"
            android:textAppearance="@style/small_indic"
            android:text="@string/view_all"/>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="top"
        android:padding="5dp"
        android:elevation="5dp"
        android:layout_marginBottom="10dp"
        android:layout_alignBottom="@id/Home_WhaitePaper_image"
        android:orientation="vertical">

        <TextView
            android:id="@+id/Home_Paper_Title"
            android:textColor="@color/White"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="@style/page_title"
            android:elevation="5dp"
            android:padding="15dp"
            android:text="The Managed \nSecurity Service " />

        <TextView
            android:id="@+id/Home_Paper_Des"
            android:textColor="@color/White"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:inputType="textMultiLine"
            android:textStyle="bold"
            android:textAppearance="@style/body"
            android:elevation="5dp"
            android:padding="15dp"
            android:text="This is a  latest Events you can see share" />

    </LinearLayout>
</RelativeLayout>

How to add a recyclerView inside another recyclerView Android Example

 

Facebooktwitterredditpinterestlinkedinmail
Recommended
Hi, Everyone In this Android Example, I am sharing how…