简体   繁体   中英

set the width of the button to the LinearLayout programmatically

I am trying to set the width of the button in the lila LinearLayout but I am getting it just like in the screenshot. How can I set the width for the button? I am facing another Problem the item number beside the checkboxes are a Little bit higher than the Level of the Checkbox. How can I configure that programmatically to set them to the same level ?

private void createRadioButton(final ArrayList<Integer> items) {

    final LinearLayout ll = (LinearLayout) findViewById(R.id.lila);
        for (int i = 0; i < items.size(); i++) {
        CheckBox cb = new CheckBox(this);
        cb.setText(items.get(i) + "\n");
        cb.setId(i + 10);
        ll.addView(cb);

    }



    Button btn = new Button(this);
    btn.setText("submit");
            // With this line below I am not getting the button displayed.
    //btn.setLayoutParams(new LinearLayout.LayoutParams(10, 40));
    ll.addView(btn);

}

Screenshot: 在此处输入图片说明

About number displayed higher than checkbox.
In your code cb.setText(items.get(i) + "\\n"); you are putting new line, so next to checkbox is diplayed number AND new line

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM