Android程式码怎么添加按钮,Android,UI 在程式中即時加上其他的UI?|?柯博文 Powen Ko...

Android,UI 在程式中即時加上其他的UI

0 Comments

25839197_1.png

柯博文 在下面介紹, 如何在Android UI 在程式中即時加上其他的UI

View tmpView;

tmpView = inflater.inflate(R.layout.login, null);

getWindow().addContentView(tmpView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

Button buttonView = new Button(this);

buttonView.setText("Button " );

getWindow().addContentView(buttonView,

new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT ViewGroup.LayoutParams.WRAP_CONTENT ));

25839197_2.jpg

// 按鈕

LayoutInflater inflater = getLayoutInflater();

View tmpView;

tmpView = inflater.inflate(R.layout.login, null);

getWindow().addContentView(tmpView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,

ViewGroup.LayoutParams.FILL_PARENT));

Button buttonView = new Button(this);

buttonView.setText("Button " );

getWindow().addContentView(buttonView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,

ViewGroup.LayoutParams.WRAP_CONTENT ));

//文字

TextView textView = new TextView(this);

textView.setText("Text View " );

@SuppressWarnings("deprecation")

AbsoluteLayout.LayoutParams abs_params =

new AbsoluteLayout.LayoutParams(

//width in pixels

100,

//height in pixels

100, 100, 100

);

getWindow().addContentView(textView,abs_params);

AbsoluteLayout as = new AbsoluteLayout(this);

TextView tvTop = new TextView(this);

tvTop.setText("top");

tvTop.setLayoutParams(new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.FILL_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT, 0, 0));

TextView tvMid = new TextView(this);

tvMid.setText("middle");

tvMid.setLayoutParams(new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.FILL_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT, 0, 80));

TextView tvright = new TextView(this);

tvright.setText("right");

tvright.setLayoutParams(new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.FILL_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT, 200, 80));

TextView tvBot = new TextView(this);

tvBot.setText("bottom");

tvBot.setLayoutParams(new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.FILL_PARENT, AbsoluteLayout.LayoutParams.WRAP_CONTENT, 0, 180));

as.addView(tvTop);

as.addView(tvMid);

as.addView(tvright);

as.addView(tvBot);

getWindow().addContentView(as,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,

ViewGroup.LayoutParams.WRAP_CONTENT ));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值