Refreshing a LinearLayout after adding a view

后端 未结 3 780
栀梦
栀梦 2020-12-03 05:35

I\'m trying to add views dynamically to a linearlayout. I see through getChildCount() that the views are added to the layout, but even calling invalidate() on the layout doe

3条回答
  •  一生所求
    2020-12-03 06:23

    I spent a lot of time to solve this problem too. And I found a simple method of refresh LinearLayout in 3 lines of code

    You must set transperent color in style.xml

    #00000000
    

    And in the code just call to set background

    LinearLayout ll = (LinearLayout) findViewById(R.id.noteList);
    ll.setBackgroundColor(getResources().getColor(R.color.transparent));
    ll.invalidate();
    

    If you has drawable background call

    ll.setBackgroundResource(R.drawable.your_drawable);
    

提交回复
热议问题