第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

Android UI 之使用java代碼實(shí)現(xiàn)動(dòng)態(tài)添加LinearLayout(一)

標(biāo)簽:
Android

so,,,现在要使用java代码去动态添加这些控件,并实现如上效果

很简单的。。。看代码。。。

    /**
     * 动态添加线性布局
     */
    private void addLinearLayout() {        //initMissionList:存储几条测试数据
        for (int i = 0; i < initMissionList().size(); i++) {            //LinearLayout默认是水平(0)居中,现在改为垂直居中
            llFmhpMissionList.setOrientation(1);            //实例化一个LinearLayout
            LinearLayout linearLayout = new LinearLayout(this);            //设置LinearLayout属性(宽和高)
            LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 120);            //设置边距
            layoutParams.setMargins(54, 0, 84, 0);            //将以上的属性赋给LinearLayout
            linearLayout.setLayoutParams(layoutParams);            //实例化一个TextView
            TextView tv = new TextView(this);            //设置宽高以及权重
            LinearLayout.LayoutParams tvParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1);            //设置textview垂直居中
            tvParams.gravity = Gravity.CENTER_VERTICAL;
            tv.setLayoutParams(tvParams);
            tv.setTextSize(14);
            tv.setTextColor(getResources().getColor(R.color.rbtn_tet));
            tv.setText(initMissionList().get(i).toString().trim());
            
            RadioGroup radioGroup = new RadioGroup(this);
            radioGroup.setLayoutParams(new RadioGroup.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 120));
            radioGroup.setOrientation(0);
            
            RadioGroup.LayoutParams rbtnParams = new RadioGroup.LayoutParams(72, 72);
            rbtnParams.gravity=Gravity.CENTER_VERTICAL;
            
            RadioGroup.LayoutParams rbtnParamsf = new RadioGroup.LayoutParams(72, 72);
            rbtnParamsf.gravity=Gravity.CENTER_VERTICAL;
            rbtnParamsf.leftMargin=84;
            rbtnParamsf.rightMargin=90;            
            final RadioButton radioButtonF = new RadioButton(this);
            radioButtonF.setLayoutParams(rbtnParamsf);
            radioButtonF.setButtonDrawable(android.R.color.transparent);
            radioButtonF.setBackground(getResources().getDrawable(R.drawable.selector_fmhp_radiobutton_x_style));            
            final RadioButton radioButtonT = new RadioButton(this);
            radioButtonT.setLayoutParams(rbtnParams);
            radioButtonT.setButtonDrawable(android.R.color.transparent);
            radioButtonT.setBackground(getResources().getDrawable(R.drawable.selector_fmhp_radiobutton_hook_style));
            
            radioGroup.addView(radioButtonF);
            radioGroup.addView(radioButtonT);
            
            linearLayout.addView(tv);
            linearLayout.addView(radioGroup);
            
            llFmhpMissionList.addView(linearLayout);
        }
         
     }

好了,基本介绍到这。。。相对来说还是比较简单。。。

原文链接:http://www.apkbus.com/blog-904057-68140.html

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報(bào)

0/150
提交
取消