Change the width of a ProgressBar added at runtime

前端 未结 3 1557
孤独总比滥情好
孤独总比滥情好 2020-12-16 04:41

I am building up a UI from code and can successfully add ProgressBar widgets, however I cannot alter the dimensions of the widget to values I need, it always stays at the de

3条回答
  •  误落风尘
    2020-12-16 05:12

    R.layout.activity includes this:

    
    

    And then the code:

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity);
        ProgressBar bar = (ProgressBar)findViewById(R.id.progress);
        bar.getLayoutParams().height = 500;
        bar.invalidate();
    }
    

    The call to the invalidate() method is important as that is when the view is redrawn to take the changes into account. Although unintuitive, it does allow for better performance by batching changes.

提交回复
热议问题