AN 动态添加布局基础

〈一〉

inflate:找到布局

LinearLayout dualmodeLayout = (LinearLayout) inflater.inflate(R.layout.dual_mode,null).findViewById(R.id.dualmodelayout);


(1)find the xml called dual_mode's layout:which id is dualmodelayout

(2)找到一个dual_mode XML文件的ID 为dualmodelayout的LinearLayout

〈二〉

浅谈五大布局:点击打开链接

〈三〉

setLayoutParams:子布局在设置在父布局中

private FrameLayout.LayoutParams params = null;
params = new FrameLayout.LayoutParams(88, 300, Gravity.RIGHT
                    | Gravity.BOTTOM);
            params.bottomMargin = playControlLayout.getHeight()
                    - bt_dualMode.getHeight();
            params.rightMargin = (screenWidth - playControlLayout.getWidth())
                    / 2 + bt_dualMode.getHeight() - 26;
            Log.i(TAG, "**showDualModeLayout**" + " "
                    + params.bottomMargin + " " + params.rightMargin + " "
                    + bt_dualMode.getBottom());
            dualmodeLayout.setLayoutParams(params);
dualmodeLaypout 是子布局,params是父布局


插入到主界面中

activityLayout.addView(dualmodeLayout, params);


希望显示出来

dualmodeLayout.setVisibility(View.VISIBLE);

希望不显示

dualmodeLayout.setVisibility(View.INVISIBLE);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值