Code example for LinearLayout

Methods: setIdsetLayoutParamssetTagaddViewsetOrientation

0
     * @param text          The text of the button 
     * @param desiredHeight The desired height of the button 
     * @return The created view. 
     */ 
    public static View doubleText(int position, Context context, String text, int desiredHeight) {
        final LinearLayout ll = new LinearLayout(context);
        ll.setOrientation(LinearLayout.HORIZONTAL);
 
        final AbsListView.LayoutParams lp =
                new AbsListView.LayoutParams(
                        ViewGroup.LayoutParams.FILL_PARENT,
                        desiredHeight);
        ll.setLayoutParams(lp);
        ll.setId(position);
         
        TextView t1 = new TextView(context);
        t1.setHeight(desiredHeight);
        t1.setText(text);
        t1.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
        final ViewGroup.LayoutParams lp1 = new LinearLayout.LayoutParams(
                0, 
                ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
        ll.addView(t1, lp1);
         
        TextView t2 = new TextView(context);
        t2.setHeight(desiredHeight);
        t2.setText(text);
        t2.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
        final ViewGroup.LayoutParams lp2 = new LinearLayout.LayoutParams(
                0, 
                ViewGroup.LayoutParams.WRAP_CONTENT,
                1.0f); 
 
        ll.addView(t2, lp2);
        ll.setTag("double");
        return ll;
    } 
 
     
    /** 
Experience pair programming with AI  Get Codota for Java