本身在shareSdk原有佈局中添加一個加載過程的佈局:java
/** 新增:分享發送進度 **/ private void setLoadingUI() { // 頁面父佈局 pageLayout = new RelativeLayout(getContext()); pageLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // 填充編輯頁佈局 RelativeLayout.LayoutParams llPageLp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); llPage.setLayoutParams(llPageLp); pageLayout.addView(llPage); // 加載過程佈局 loadReLayout = new RelativeLayout(getContext()); loadReLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); loadReLayout.setClickable(true); loadReLayout.setBackgroundColor(0x50000000); loadReLayout.setVisibility(View.GONE); pageLayout.addView(loadReLayout); // 加載過程當中間佈局 LinearLayout loadCenterLayout = new LinearLayout(getContext()); RelativeLayout.LayoutParams lcLp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lcLp.addRule(RelativeLayout.CENTER_IN_PARENT); loadCenterLayout.setPadding(8, 8, 8, 8); loadCenterLayout.setBackgroundColor(0xa5000000); loadCenterLayout.setOrientation(LinearLayout.HORIZONTAL); loadReLayout.addView(loadCenterLayout, lcLp); // 進度條和加載中說明 ProgressBar pb = new ProgressBar(getContext()); pb.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); loadCenterLayout.addView(pb); TextView loadText = new TextView(getContext()); LayoutParams ltlp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ltlp.setMargins(8, 0, 0, 0); ltlp.gravity = Gravity.CENTER_VERTICAL; loadText.setLayoutParams(ltlp); loadText.setText("正在轉發分享..."); loadText.setTextSize(16); loadText.setTextColor(Color.WHITE); loadCenterLayout.addView(loadText); }
原佈局部分代碼:ide
private void initPageView() { // 編輯頁父佈局 llPage = new LinearLayout(getContext()); llPage.setBackgroundColor(0xff323232); llPage.setOrientation(LinearLayout.VERTICAL); // 新增:分享發送過程 setLoadingUI(); // 標題欄 llTitle = new TitleLayout(getContext()); llTitle.setBackgroundResource(R.drawable.title_back); llTitle.getBtnBack().setOnClickListener(this); llTitle.getTvTitle().setText(R.string.multi_share); llTitle.getBtnRight().setVisibility(View.VISIBLE); llTitle.getBtnRight().setText(R.string.share); llTitle.getBtnRight().setOnClickListener(this); llTitle.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); llPage.addView(llTitle); FrameLayout flPage = new FrameLayout(getContext()); LinearLayout.LayoutParams lpFl = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); lpFl.weight = 1; flPage.setLayoutParams(lpFl); llPage.addView(flPage); // 頁面主體 LinearLayout llBody = new LinearLayout(getContext()); llBody.setOrientation(LinearLayout.VERTICAL); FrameLayout.LayoutParams lpLl = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); lpLl.gravity = Gravity.LEFT | Gravity.TOP; llBody.setLayoutParams(lpLl); flPage.addView(llBody); // 別針圖片 ivPin = new ImageView(getContext()); ivPin.setImageResource(R.drawable.pin); int dp_80 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 80); int dp_36 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 36); FrameLayout.LayoutParams lpPin = new FrameLayout.LayoutParams(dp_80, dp_36); lpPin.topMargin = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 6); lpPin.gravity = Gravity.RIGHT | Gravity.TOP; ivPin.setLayoutParams(lpPin); flPage.addView(ivPin); ImageView ivShadow = new ImageView(getContext()); ivShadow.setBackgroundResource(R.drawable.title_shadow); ivShadow.setImageResource(R.drawable.title_shadow); FrameLayout.LayoutParams lpSd = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); ivShadow.setLayoutParams(lpSd); flPage.addView(ivShadow); LinearLayout llInput = new LinearLayout(getContext()); llInput.setMinimumHeight(cn.sharesdk.framework.utils.R.dipToPx(getContext(), 150)); llInput.setBackgroundResource(R.drawable.edittext_back); LinearLayout.LayoutParams lpInput = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); int dp_3 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 3); lpInput.setMargins(dp_3, dp_3, dp_3, dp_3); lpInput.weight = 1; llInput.setLayoutParams(lpInput); llBody.addView(llInput); //... }
效果圖:佈局