android 生專屬分享卡
知識點1:View 檢視可以啟用繪圖快取
知識點2:從layout xml佈局檔案載入View檢視
知識點3:View影片的測量,定位,
知識點4:獲取圖片
1.View如何啟用繪圖快取
View.setDrawingCacheEnabled(true) 方法
2.從layout xml佈局檔案載入View檢視
LayoutInflater.from(context).inflate() 方法
3.View影片的測量,定位。因為自己載入的View 沒有父檢視,所以需要自己去測量大小,定位位置
View.measure() 方法
4.根據影片獲取圖片
Bitmap bitmapss = View.getDrawingCache();
例項程式碼:
public Bitmap getShareCardBitmap(int avatarId,String nickName,String desc) {
//載入分享卡布局檔案
View shareCardView = LayoutInflater.from(getContext()).inflate(R.layout.hy_share_card, null);
ImageView avatarImg = shareCardView.findViewById(R.id.avatar_img);
TextView nickNameTv = shareCardView.findViewById(R.id.nick_name_tv);
TextView descTv = shareCardView.findViewById(R.id.title_tv);
avatarImg.setImageResource(avatarId);
nickNameTv.setText(nickName);
descTv.setText(desc);
//開啟繪圖快取
shareCardView.setDrawingCacheEnabled(true);
//測量大小
shareCardView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
//佈局定位
shareCardView.layout(0, 0, shareCardView.getMeasuredWidth(), shareCardView.getMeasuredHeight());
return shareCardView.getDrawingCache();
}
android 生專屬分享卡
知識點1:View 檢視可以啟用繪圖快取
知識點2:從layout xml佈局檔案載入View檢視
知識點3:View影片的測量,定位,
知識點4:獲取圖片
1.View如何啟用繪圖快取
View.setDrawingCacheEnabled(true) 方法
2.從layout xml佈局檔案載入View檢視
LayoutInflater.from(context).inflate() 方法
3.View影片的測量,定位。因為自己載入的View 沒有父檢視,所以需要自己去測量大小,定位位置
View.measure() 方法
4.根據影片獲取圖片
Bitmap bitmapss = View.getDrawingCache();
例項程式碼:
public Bitmap getShareCardBitmap(int avatarId,String nickName,String desc) {
//載入分享卡布局檔案
View shareCardView = LayoutInflater.from(getContext()).inflate(R.layout.hy_share_card, null);
ImageView avatarImg = shareCardView.findViewById(R.id.avatar_img);
TextView nickNameTv = shareCardView.findViewById(R.id.nick_name_tv);
TextView descTv = shareCardView.findViewById(R.id.title_tv);
avatarImg.setImageResource(avatarId);
nickNameTv.setText(nickName);
descTv.setText(desc);
//開啟繪圖快取
shareCardView.setDrawingCacheEnabled(true);
//測量大小
shareCardView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
//佈局定位
shareCardView.layout(0, 0, shareCardView.getMeasuredWidth(), shareCardView.getMeasuredHeight());
return shareCardView.getDrawingCache();
}