Code example for RelativeLayout.LayoutParams

Methods: addRule

0
         * Each layout manager has its own layout parameters that allow to 
         * express rules how a widgets should be positioned. The WRAP_CONTENT 
         * parameters specify that the widget should be sized to its natural 
         * size (for both width and height). 
         */ 
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        /* 
         * Add a rule that specifies that the widget should be centered relative 
         * to the enclosing container. It is instructional to pass different 
         * layout parameters as defined in RelativeLayout (such as 
         * RelativeLayout.ALIGN_PARENT_BOTTOM). 
         */ 
        params.addRule(RelativeLayout.CENTER_IN_PARENT);
 
        /* 
         * Add the label as a child to the RelativeLayout using the specific 
         * layout parameters. 
         */ 
        layout.addView(label, params);
Experience pair programming with AI  Get Codota for Java