简体   繁体   English

RecyclerView Item Layout 截取当前 ItemLayout 的截图

[英]RecyclerView Item Layout take screenshot of current ItemLayout

I am new to android development,I have a recyclerview in which i am inflating different custom views like Need Employee, NeedCofounder etc .我是 android 开发的新手,我有一个 recyclerview,我在其中膨胀了不同的自定义视图,如 Need Employee、NeedCo Founder 等。 I am trying to add a feature to share these posts on social media , what i cannot figure out is how to get the current view that the user has selected to share .我正在尝试添加一项功能以在社交媒体上分享这些帖子,但我无法弄清楚如何获取用户选择分享的当前视图。 thank you谢谢你

package com.devs.bevy.homeScreen.holders;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatCheckBox;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

import com.devs.bevy.R;
import com.facebook.drawee.view.SimpleDraweeView;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

public class BevyPostViewHolder {

    public static class MainHolder extends RecyclerView.ViewHolder{
        public @Nullable @BindView(R.id.userImage) CircleImageView userImage;
        public @Nullable @BindView(R.id.userName) AppCompatTextView userName;
        public @Nullable @BindView(R.id.postTime) AppCompatTextView postTime;
        public @Nullable @BindView(R.id.postType) AppCompatTextView postType;
        public @Nullable @BindView(R.id.btnAddToWishList) AppCompatCheckBox btnAddToWishList;
        public @Nullable @BindView(R.id.messageWindow) AppCompatImageView messageWindow;
        public @Nullable @BindView(R.id.commentWindow) AppCompatImageView commentWindow;
        public @Nullable @BindView(R.id.commentCount) AppCompatTextView commentCount;
        public @Nullable @BindView(R.id.markDoneUndone) AppCompatCheckBox markDoneUndone;
        public @Nullable @BindView(R.id.deletePost) AppCompatImageView deletePost;
        public @Nullable @BindView(R.id.sharePost) AppCompatImageView sharePost;

        public MainHolder(View itemView) {
            super(itemView);
        }
    }

    public static class NeedCoFounder extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.experience) AppCompatTextView experience;
        public @BindView(R.id.location) AppCompatTextView location;
        public @BindView(R.id.profile) AppCompatTextView profile;
        public @BindView(R.id.equity) AppCompatTextView equity;
        public @BindView(R.id.salary) AppCompatTextView salary;
        public @BindView(R.id.description) AppCompatTextView description;

        public NeedCoFounder(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class NeedEmployee extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.experience) AppCompatTextView experience;
        public @BindView(R.id.location) AppCompatTextView location;
        public @BindView(R.id.profile) AppCompatTextView profile;
        public @BindView(R.id.equity) AppCompatTextView equity;
        public @BindView(R.id.salary) AppCompatTextView salary;
        public @BindView(R.id.description) AppCompatTextView description;

        public NeedEmployee(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class NeedIntern extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.location) AppCompatTextView location;
        public @BindView(R.id.profile) AppCompatTextView profile;
        public @BindView(R.id.stipend) AppCompatTextView stipend;
        public @BindView(R.id.description) AppCompatTextView description;

        public NeedIntern(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class NeedFreelancer extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.experience) AppCompatTextView experience;
        public @BindView(R.id.profile) AppCompatTextView profile;
        public @BindView(R.id.price) AppCompatTextView price;
        public @BindView(R.id.description) AppCompatTextView description;

        public NeedFreelancer(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class NeedOffice extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.type) AppCompatTextView type;
        public @BindView(R.id.location) AppCompatTextView location;
        public @BindView(R.id.description) AppCompatTextView description;
        public @BindView(R.id.price) AppCompatTextView price;

        public NeedOffice(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class NeedEntities extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.type) AppCompatTextView type;
        public @BindView(R.id.location) AppCompatTextView location;
        public @BindView(R.id.description) AppCompatTextView description;
        public @BindView(R.id.price) AppCompatTextView price;
        public @BindView(R.id.entitiesName) AppCompatTextView entitiesName;

        public NeedEntities(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class NeedMentor extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.speciality) AppCompatTextView speciality;
        public @BindView(R.id.description) AppCompatTextView description;

        public NeedMentor(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class OfferCoFounder extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.experience) AppCompatTextView experience;
        public @BindView(R.id.location) AppCompatTextView location;
        public @BindView(R.id.profile) AppCompatTextView profile;
        public @BindView(R.id.description) AppCompatTextView description;

        public OfferCoFounder(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class OfferEmployee extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.experience) AppCompatTextView experience;
        public @BindView(R.id.location) AppCompatTextView location;
        public @BindView(R.id.profile) AppCompatTextView profile;
        public @BindView(R.id.description) AppCompatTextView description;
        public @BindView(R.id.salary) AppCompatTextView salary;

        public OfferEmployee(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class OfferIntern extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.location) AppCompatTextView location;
        public @BindView(R.id.profile) AppCompatTextView profile;
        public @BindView(R.id.stipend) AppCompatTextView stipend;
        public @BindView(R.id.description) AppCompatTextView description;

        public OfferIntern(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    public static class OfferFreelancer extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.experience) AppCompatTextView experience;
        public @BindView(R.id.profile) AppCompatTextView profile;
        public @BindView(R.id.price) AppCompatTextView price;
        public @BindView(R.id.description) AppCompatTextView description;

        public OfferFreelancer(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class OfferOffice extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.type) AppCompatTextView type;
        public @BindView(R.id.location) AppCompatTextView location;
        public @BindView(R.id.description) AppCompatTextView description;
        public @BindView(R.id.price) AppCompatTextView price;
        public @BindView(R.id.officeImage) SimpleDraweeView officeImage;
        public @BindView(R.id.officeImageCount) AppCompatTextView officeImageCount;
        public @BindView(R.id.imageLayout) RelativeLayout imageLayout;

        public OfferOffice(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class OfferEntities extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.type) AppCompatTextView type;
        public @BindView(R.id.location) AppCompatTextView location;
        public @BindView(R.id.description) AppCompatTextView description;
        public @BindView(R.id.price) AppCompatTextView price;
        public @BindView(R.id.entitiesImage) SimpleDraweeView entitiesImage;
        public @BindView(R.id.entitiesImageCount) AppCompatTextView entitiesImageCount;
        public @BindView(R.id.imageLayout) RelativeLayout imageLayout;

        public OfferEntities(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }

    public static class OfferMentor extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.speciality) AppCompatTextView speciality;
        public @BindView(R.id.description) AppCompatTextView description;

        public OfferMentor(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    public static class GpIdeaValidation extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.domain) AppCompatTextView domain;
        public @BindView(R.id.title) AppCompatTextView title;
        public @BindView(R.id.query) AppCompatTextView query;

        public GpIdeaValidation(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class GpOptimizeCashFlow extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.title) AppCompatTextView title;
        public @BindView(R.id.description) AppCompatTextView description;

        public GpOptimizeCashFlow(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static class GpTeam extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.profile) AppCompatTextView profile;
        public @BindView(R.id.description) AppCompatTextView description;

        public GpTeam(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class GpCompetitorAnalysis extends MainHolder {

        public GpCompetitorAnalysis(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class GpProductPricing extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.currentPrice) AppCompatTextView currentPrice;
        public @BindView(R.id.description) AppCompatTextView description;
        public @BindView(R.id.shortDescription) AppCompatTextView shortDescription;

        public GpProductPricing(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static class GpProductReview extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.description) AppCompatTextView description;
        public @BindView(R.id.website) AppCompatTextView website;
        public @BindView(R.id.questions) AppCompatTextView questions;

        public GpProductReview(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static class GpBusinessModel extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.title) AppCompatTextView title;
        public @BindView(R.id.description) AppCompatTextView description;

        public GpBusinessModel(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static class GpMarketing extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.title) AppCompatTextView title;
        public @BindView(R.id.description) AppCompatTextView description;

        public GpMarketing(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static class GpCustomerVoices extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.description) AppCompatTextView description;

        public GpCustomerVoices(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static class GpMarketAnalysis extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.role1) AppCompatTextView role1;
        public @BindView(R.id.location) AppCompatTextView location;
        public @BindView(R.id.title) AppCompatTextView title;
        public @BindView(R.id.when) AppCompatTextView when;

        public GpMarketAnalysis(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static class GpGetMotivation extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.description) AppCompatTextView description;

        public GpGetMotivation(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static class GpPivotAnalysis extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.brief) AppCompatTextView brief;
        public @BindView(R.id.query) AppCompatTextView query;
        public @BindView(R.id.title) AppCompatTextView title;

        public GpPivotAnalysis(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static class GpNeedInvestor extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.domains) AppCompatTextView domains;
        public @BindView(R.id.title) AppCompatTextView title;
        public @BindView(R.id.highLevelPitch) AppCompatTextView highLevelPitch;
        public @BindView(R.id.description) AppCompatTextView description;
        public @BindView(R.id.attachment) AppCompatTextView attachment;

        public GpNeedInvestor(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static class GpLegal extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.issues) AppCompatTextView issues;
        public @BindView(R.id.query) AppCompatTextView query;

        public GpLegal(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static class GpNetworking extends MainHolder {
        public @BindView(R.id.role) AppCompatTextView role;
        public @BindView(R.id.description) AppCompatTextView description;

        public GpNetworking(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public static class GpOther extends MainHolder {
        public @BindView(R.id.title) AppCompatTextView title;
        public @BindView(R.id.description) AppCompatTextView description;

        public GpOther(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

/*PROGRESS BAR HOLDERS*/

    public static class ProgressViewHolder extends MainHolder {
        public @BindView(R.id.progressBar) ProgressBar progressBar;

        public ProgressViewHolder(View v) {
            super(v);
            try {
                ButterKnife.bind(this, v);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

Every layout has a different xml file每个布局都有不同的 xml 文件

i am trying to take a screenshot like this我正在尝试截取这样的屏幕截图

public Bitmap takeScreenshot() {

        // Cannot figure out how to get the current view 
        View rootView = ????
        rootView.setDrawingCacheEnabled(true);
        return rootView.getDrawingCache();
    }

SharePost button分享帖子按钮

 holder.sharePost.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Bitmap bitmap = takeScreenshot();
        }
    });
   holder.sharePost.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bitmap bitmap = takeScreenshot();
//getAdapterPosition() will return position of a listview, from that list you can take holder.rootview
            }
        });

RecyclerViewAdapter.class RecyclerViewAdapter.class

private View.OnClickListener globalClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int selectedPosition = (int) v.getTag();
                // Save selectedPositions on list or do something              
                Bitmap bitmap = takeScreenshot();
            }
        }

RecyclerViewAdapter.onBindViewHolder RecyclerViewAdapter.onBindViewHolder

holder.sharePost.setTag(position);
holder.sharePost.setOnClickListener(globalClickListener);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM