android移动布局,Android笔记:代码编写布局

Android笔记:代码编写布局

发布时间:2020-07-15 05:07:48

来源:51CTO

阅读:1028

作者:glblong

自己在shareSdk原有布局中添加一个加载过程的布局:/** 新增:分享发送进度 **/

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);

}

原布局部分代码: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);

//...

}

效果图:

f85b388af4c347f08541d10d88fa0b89.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值