Android - How to make an progressBar touching a bottom screen border

前端 未结 5 541
春和景丽
春和景丽 2021-01-24 23:30

I want a ProgressBar that is touching a bottom border of screen but with this piece of code, I am getting an little space between bar and screen border:



        
5条回答
  •  臣服心动
    2021-01-25 00:31

    I have been struggling with this for a while now. My conclusion: There is no way to archieve this behaviour with XML for arbitrary screen sizes. On some screen sesolutions the progress bar will always be misplaced a little.

    My simple solution: Set the Y of the progressbar programmatically to the Y of the super view/layout

    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
    
        progressBar.setY(layout.getY() - progressBar.getHeight() / 2);
    }
    

    Works like a charm and for all screen sizes.

提交回复
热议问题