亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在Android中動態地將TextView添加到LinearLayout?

如何在Android中動態地將TextView添加到LinearLayout?

瀟瀟雨雨 2019-09-02 15:44:14
我嘗試將添加TextView到LinearLayout動態,如下面的代碼,但是當我運行該應用程序也不會出現?setContentView(R.layout.advanced);m_vwJokeLayout=(LinearLayout) this.findViewById(R.id.m_vwJokeLayout);m_vwJokeEditText=(EditText) this.findViewById(R.id.m_vwJokeEditText);m_vwJokeButton=(Button) this.findViewById(R.id.m_vwJokeButton);TextView tv=new TextView(this);tv.setText("test");this.m_vwJokeLayout.addView(tv);有什么問題?
查看完整描述

3 回答

?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

LayoutParams lparams = new LayoutParams(

   LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

TextView tv=new TextView(this);

tv.setLayoutParams(lparams);

tv.setText("test");

this.m_vwJokeLayout.addView(tv);

您可以根據需要更改lparams


查看完整回答
反對 回復 2019-09-02
  • 3 回答
  • 0 關注
  • 1496 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號