自定义布局蒙层和标题按钮位置代码控制移动位置 而不是一张图
final RelativeLayout private_desc_back = new RelativeLayout(mContext);
private_desc_back.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
private_desc_back.setBackgroundResource(R.drawable.private_share_desc_popuwind);
private_desc_back.setGravity(Gravity.CENTER);
final ImageView landing_img = new ImageView(mContext);
RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT );
landing_img.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@SuppressLint("NewApi")
@Override
public void onGlobalLayout() {
landing_img.getViewTreeObserver().removeGlobalOnLayoutListener(this);
LogUtil.v(TAG, "=========test OnGlobalLayoutListener==========");
int topMargin = priShareView.getTop();
int eftMargin = priShareView.getLeft();
int rightMargin = priShareView.getRight();
int bottomMargin = priShareView.getBottom();
int cenx1 = (rightMargin + eftMargin) / 2;
int cenY1 = (bottomMargin + topMargin) / 2;
int topMargin1 = landing_img.getTop();
int eftMargin1 = landing_img.getLeft();
int rightMargin1 = landing_img.getRight();
int bottomMargin1 = landing_img.getBottom();
int cenx2 = (rightMargin1 + eftMargin1) / 2;
int cenY2 = (bottomMargin1 + topMargin1) / 2;
landing_img.scrollTo(cenx2 - cenx1, cenY2 - cenY1);
}
});
share_desc.setClickable(false);
private_desc_back.addView(landing_img, params);
landing_img.setImageResource(R.drawable.landing_desc_1);
landing_img.setScaleType(ScaleType.CENTER);
private_desc_back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
private_desc_back.setVisibility(View.GONE);
share_desc.setClickable(true);
}
});
fl_content.addView(private_desc_back);
}