1. 程式人生 > >在LinearLayout裡動態新增子佈局

在LinearLayout裡動態新增子佈局

  1. //初始化佈局

  2. LinearLayout mContentLayout = (LinearLayout) findViewById(R.id.lin_control);

  3. //迴圈新增資料

  4. private void setTextShopingView() {

  5. mContentLayout.removeAllViews();

  6. if (Info.getData() != null && Info.getData().size() > 0) {

  7. LinearLayout  childLayout=  (LinearLayout)mLayoutInflater.inflate(

  8. R.layout.child_layout, null);

  9. ImageView mImge= (ImageView) childLayout

  10. .findViewById(R.id.image);

  11. TextView mText= (TextView) childLayout

  12. .findViewById(R.id.txt);

  13. mContentLayout.addView(childLayout);

  14. mContentLayout.setVisibility(View.VISIBLE);

  15. } else {

  16. mContentLayout.setVisibility(View.GONE);

  17. }

  18. }