How to have Image and Text Center within a Button

后端 未结 12 2253
感动是毒
感动是毒 2020-12-02 15:48

I want to display TEXT and Icon on a Button.

+----------------------------+
|          Icon TEXT         |
+---------------------         


        
12条回答
  •  忘掉有多难
    2020-12-02 15:54

    You can just set a padding depending on button size and image size:

    Button button1 = null;
    //initialize button….
    ViewGroup.LayoutParams params = button1.getLayoutParams();
    int btn1Width = ((int) (0.33 * (double)ecranWidth));
    params.width = btn1Width;
    button1.setLayoutParams(params);
    button1.setPadding((btn1Width/2-9), 0, 0, 0);
    //where (btn1Width/2-9)   =   size of button divided on 2 minux half size of icon… 
    

提交回复
热议问题