Example usage for android.widget LinearLayout setLayoutParams

List of usage examples for android.widget LinearLayout setLayoutParams

Introduction

In this page you can find the example usage for android.widget LinearLayout setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:ovh.ice.icecons.MainActivity.java

private void createLayout() {

    // main centered layout

    LinearLayout.LayoutParams smallLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f);
    float scale = IceScreenUtils.densityScale(getApplicationContext());
    ViewGroup.LayoutParams buttonParams = new ViewGroup.LayoutParams(Math.round(48 * scale),
            Math.round(48 * scale));

    LinearLayout frameLayout = new LinearLayout(this);
    frameLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT));
    frameLayout.setBackgroundColor(0xffffffff);
    frameLayout.setGravity(Gravity.CENTER);
    setContentView(frameLayout);//from  ww w  .java 2s .  com

    LinearLayout baseLayout = new LinearLayout(this);
    baseLayout.setOrientation(LinearLayout.VERTICAL);
    baseLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));
    baseLayout.setGravity(Gravity.LEFT);
    frameLayout.addView(baseLayout);

    // wallpaper button

    LinearLayout wallpaperLayout = new LinearLayout(this);
    wallpaperLayout.setOrientation(LinearLayout.HORIZONTAL);
    wallpaperLayout.setLayoutParams(smallLayoutParams);
    wallpaperLayout.setGravity(Gravity.CENTER_VERTICAL);
    baseLayout.addView(wallpaperLayout);

    LinearLayout wallpaperClickLayout = new LinearLayout(this);
    wallpaperClickLayout.setOrientation(LinearLayout.HORIZONTAL);
    wallpaperClickLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    wallpaperClickLayout.setGravity(Gravity.CENTER);
    wallpaperLayout.addView(wallpaperClickLayout);
    wallpaperClickLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            wallpaperPicker(v);
        }
    });

    Button wallpaperButton = new Button(this);
    wallpaperButton.setLayoutParams(buttonParams);
    wallpaperButton.setBackground(
            new BitmapDrawable(getResources(), IceImageUtils.bitmapLoad(getApplicationContext().getResources(),
                    R.drawable.ic_wallpaper_button, Math.round(48 * scale), Math.round(48 * scale))));
    wallpaperClickLayout.addView(wallpaperButton);

    TextView wallpaperText = new TextView(this);
    wallpaperText.setText("wallpapers");
    wallpaperText.setTextSize(24);
    wallpaperText.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
    wallpaperText.setPadding(64, 64, 64, 64);
    wallpaperClickLayout.addView(wallpaperText);

    // icon view button

    LinearLayout iconLayout = new LinearLayout(this);
    iconLayout.setOrientation(LinearLayout.HORIZONTAL);
    iconLayout.setLayoutParams(smallLayoutParams);
    iconLayout.setGravity(Gravity.CENTER_VERTICAL);
    baseLayout.addView(iconLayout);

    LinearLayout iconClickLayout = new LinearLayout(this);
    iconClickLayout.setOrientation(LinearLayout.HORIZONTAL);
    iconClickLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    iconClickLayout.setGravity(Gravity.CENTER);
    iconLayout.addView(iconClickLayout);
    iconClickLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            iconView(v);
        }
    });

    Button iconButton = new Button(this);
    iconButton.setLayoutParams(buttonParams);
    iconButton.setBackground(
            new BitmapDrawable(getResources(), IceImageUtils.bitmapLoad(getApplicationContext().getResources(),
                    R.drawable.ic_icon_button, Math.round(48 * scale), Math.round(48 * scale))));
    iconClickLayout.addView(iconButton);

    TextView iconText = new TextView(this);
    iconText.setText("view icons");
    iconText.setTextSize(24);
    iconText.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
    iconText.setPadding(64, 64, 64, 64);
    iconClickLayout.addView(iconText);

    // source code button

    LinearLayout sourceLayout = new LinearLayout(this);
    sourceLayout.setOrientation(LinearLayout.HORIZONTAL);
    sourceLayout.setLayoutParams(smallLayoutParams);
    sourceLayout.setGravity(Gravity.CENTER_VERTICAL);
    baseLayout.addView(sourceLayout);

    LinearLayout sourceClickLayout = new LinearLayout(this);
    sourceClickLayout.setOrientation(LinearLayout.HORIZONTAL);
    sourceClickLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    sourceClickLayout.setGravity(Gravity.CENTER);
    sourceLayout.addView(sourceClickLayout);
    sourceClickLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            gitLink(v);
        }
    });

    Button sourceButton = new Button(this);
    sourceButton.setLayoutParams(buttonParams);
    sourceButton.setBackground(
            new BitmapDrawable(getResources(), IceImageUtils.bitmapLoad(getApplicationContext().getResources(),
                    R.drawable.ic_source_button, Math.round(48 * scale), Math.round(48 * scale))));
    sourceClickLayout.addView(sourceButton);

    TextView sourceText = new TextView(this);
    sourceText.setText("source code");
    sourceText.setTextSize(24);
    sourceText.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
    sourceText.setPadding(64, 64, 64, 64);
    sourceClickLayout.addView(sourceText);

    // license button

    LinearLayout aboutLayout = new LinearLayout(this);
    aboutLayout.setOrientation(LinearLayout.HORIZONTAL);
    aboutLayout.setLayoutParams(smallLayoutParams);
    aboutLayout.setGravity(Gravity.CENTER_VERTICAL);
    baseLayout.addView(aboutLayout);

    LinearLayout aboutClickLayout = new LinearLayout(this);
    aboutClickLayout.setOrientation(LinearLayout.HORIZONTAL);
    aboutClickLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    aboutClickLayout.setGravity(Gravity.CENTER);
    aboutLayout.addView(aboutClickLayout);
    aboutClickLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            licenseShow(v);
        }
    });

    Button aboutButton = new Button(this);
    aboutButton.setLayoutParams(buttonParams);
    aboutButton.setBackground(
            new BitmapDrawable(getResources(), IceImageUtils.bitmapLoad(getApplicationContext().getResources(),
                    R.drawable.ic_license_button, Math.round(48 * scale), Math.round(48 * scale))));
    aboutClickLayout.addView(aboutButton);

    TextView aboutText = new TextView(this);
    aboutText.setText("license");
    aboutText.setTextSize(24);
    aboutText.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
    aboutText.setPadding(64, 64, 64, 64);
    aboutClickLayout.addView(aboutText);

}

From source file:com.ntsync.android.sync.activities.AccountListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Context context = view.getContext();
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);

    Button loginBtn = new Button(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);/*w  w w .j  av a  2 s  . c om*/
    layoutParams.rightMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            view.getResources().getDisplayMetrics());
    loginBtn.setLayoutParams(layoutParams);
    loginBtn.setText(context.getResources().getText(R.string.accountlist_login_button));
    loginBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            startLoginView();
        }
    });

    Button createAccountBtn = new Button(context);
    createAccountBtn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    createAccountBtn.setText(context.getResources().getText(R.string.accountlist_creataccount_button));
    createAccountBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            createAccountView();
        }
    });

    linearLayout.addView(loginBtn);
    linearLayout.addView(createAccountBtn);
    ((ViewGroup) this.getListView().getParent()).addView(linearLayout);
    this.getListView().setEmptyView(linearLayout);
}

From source file:com.example.hllut.app.Deprecated.MainActivity.java

/**
 * fill the "liters of petrol" textView, as well as drawing the petrol barrels
 *//*from   w w  w.  java 2 s. co  m*/
private void drawPetrol() {
    //TODO use the bundle
    float litersOfPetrol = (TOTAL_CO2 / CO2_PER_LITRE_PETROL);

    TextView tv = (TextView) findViewById(R.id.litersTextView);
    tv.setText("Burning " + String.format("%.2f", litersOfPetrol) + " liters of petrol");

    TableLayout layout = (TableLayout) findViewById(R.id.petrolContainer);

    TableRow newRow = new TableRow(this);
    LinearLayout linLay = new LinearLayout(this);

    linLay.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT, 1f));

    newRow.setLayoutParams(
            new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
    newRow.setPadding(10, 10, 10, 10);

    for (int i = 1; i < (int) litersOfPetrol + 1; i++) { //
        // TODO: To many images fuck up formatting
        // Create images
        ImageView im = new ImageView(this);
        im.setImageResource(R.drawable.oil_barrel);
        im.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));

        //barrells per row = 7
        if (i % 7 == 0) {
            // if you have gone 7 laps
            // print what you have
            linLay.addView(im);
            newRow.addView(linLay,
                    new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));

            layout.addView(newRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
                    TableLayout.LayoutParams.WRAP_CONTENT));

            newRow = new TableRow(this);
            linLay = new LinearLayout(this);

            linLay.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT, 1f));

            newRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT));
            newRow.setPadding(10, 10, 10, 10);
        } else {
            linLay.addView(im);
        }

    }

    newRow.addView(linLay, new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));

    layout.addView(newRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
            TableLayout.LayoutParams.WRAP_CONTENT));
}

From source file:net.xisberto.work_schedule.PeriodListAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.period_list_item, null);
    }//ww  w. j  av  a 2s  .c  om

    final Period period = (Period) getItem(position);

    ((TextView) convertView.findViewById(R.id.period_label)).setText(context.getString(period.getLabelId()));

    ((TextView) convertView.findViewById(R.id.period_time))
            .setText(period.formatTime(DateFormat.is24HourFormat(context)));

    CompoundButton check_alarm = (CompoundButton) convertView.findViewById(R.id.check_alarm);
    if (show_checkboxes) {
        check_alarm.setChecked(period.enabled);
        check_alarm.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View check_box) {
                boolean isChecked = ((CompoundButton) check_box).isChecked();
                period.enabled = isChecked && (period.time.getTimeInMillis() > System.currentTimeMillis());
                period.setAlarm(context, true);
                period.persist(context);
                ((CompoundButton) check_box).setChecked(period.enabled);
            }
        });
    } else {
        check_alarm.setVisibility(View.GONE);
        LinearLayout layout_labels = (LinearLayout) convertView.findViewById(R.id.layout_labels);
        LayoutParams params = (LayoutParams) layout_labels.getLayoutParams();
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
        layout_labels.setLayoutParams(params);
    }

    return convertView;
}

From source file:com.example.hllut.app.Deprecated.MainActivity.java

/**
 * Fills "amount of planets" textView as well as drawing the planets
 *//*  ww w. jav a2  s  .c om*/
private void drawPlanets() {
    //TODO use the bundle
    int numberOfPlanets = (int) (TOTAL_CO2 / MAX_CO2_PER_PERSON);
    TextView need = (TextView) findViewById(R.id.planetsTextView);
    need.setText("We would need " + numberOfPlanets + " planets");

    TableLayout layout = (TableLayout) findViewById(R.id.planetContainer);

    TableRow tbr = new TableRow(this);

    LinearLayout linearLayout = new LinearLayout(this);

    linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); //TODO

    tbr.setLayoutParams(
            new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT));
    tbr.setPadding(10, 10, 10, 10);

    for (int i = 1; i < numberOfPlanets + 1; i++) {
        // TODO: Too many planets fuck up formatting
        // Create images
        ImageView im = new ImageView(this);
        im.setImageResource(R.drawable.earth);
        im.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
        im.setPadding(10, 10, 10, 10);

        //planets per row = 5
        if (i % 5 == 0) {
            // if you have gone 5 laps
            // print what you have
            linearLayout.addView(im);
            tbr.addView(linearLayout,
                    new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1f));

            layout.addView(tbr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                    TableLayout.LayoutParams.MATCH_PARENT));

            tbr = new TableRow(this);
            linearLayout = new LinearLayout(this);

            linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT, 1f));

            tbr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
                    TableRow.LayoutParams.MATCH_PARENT));
            tbr.setPadding(10, 10, 10, 10);
        } else {
            linearLayout.addView(im);
        }

    }

    tbr.addView(linearLayout,
            new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1f)); //

    layout.addView(tbr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
            TableLayout.LayoutParams.MATCH_PARENT));
}

From source file:com.umeng.comm.ui.emoji.EmojiBorad.java

/**
 * </br>/*from   ww  w  . jav  a 2 s  .  c o  m*/
 * 
 * @return
 */
private ViewGroup createPointLinearlayout() {
    LinearLayout pointContainerLayout = new LinearLayout(getContext());
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    pointContainerLayout.setLayoutParams(params);
    pointContainerLayout.setOrientation(LinearLayout.HORIZONTAL);
    pointContainerLayout.setGravity(Gravity.CENTER);
    params.gravity = Gravity.CENTER;
    params.topMargin = DeviceUtils.dp2px(getContext(), 15);
    params.bottomMargin = DeviceUtils.dp2px(getContext(), 15);
    return pointContainerLayout;
}

From source file:eu.geopaparazzi.library.forms.views.GTimeView.java

/**
 * @param fragment the fragment.//  w ww  .  j a va 2 s.  com
 * @param attrs attributes.
 * @param parentView parent
 * @param key key
 * @param value value
 * @param constraintDescription constraints
 * @param readonly if <code>false</code>, the item is disabled for editing.
 */
public GTimeView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String key, String value,
        String constraintDescription, boolean readonly) {
    super(fragment.getActivity(), attrs);

    Context context = fragment.getActivity();

    LinearLayout textLayout = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    textLayout.setLayoutParams(layoutParams);
    textLayout.setOrientation(LinearLayout.VERTICAL);
    parentView.addView(textLayout);

    TextView textView = new TextView(context);
    textView.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    textView.setPadding(2, 2, 2, 2);
    textView.setText(key.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
    textView.setTextColor(context.getResources().getColor(R.color.formcolor));
    textLayout.addView(textView);

    button = new Button(context);
    button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    button.setPadding(15, 5, 15, 5);

    final SimpleDateFormat timeFormatter = TimeUtilities.INSTANCE.TIMEONLY_FORMATTER;
    if (value == null || value.length() == 0) {
        String dateStr = timeFormatter.format(new Date());
        button.setText(dateStr);
    } else {
        button.setText(value);
    }
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String dateStr = button.getText().toString();
            Date date = null;
            try {
                date = timeFormatter.parse(dateStr);
            } catch (ParseException e) {
                // fallback on current date
                date = new Date();
            }
            final Calendar c = Calendar.getInstance();
            c.setTime(date);
            int hourOfDay = c.get(Calendar.HOUR_OF_DAY);
            int minute = c.get(Calendar.MINUTE);

            FormTimePickerFragment newFragment = new FormTimePickerFragment();
            newFragment.setAttributes(hourOfDay, minute, true, button);
            newFragment.show(fragment.getFragmentManager(), "timePicker");
        }
    });
    button.setEnabled(!readonly);

    textLayout.addView(button);
}

From source file:eu.geopaparazzi.library.forms.views.GDateView.java

/**
 * @param fragment   the fragment to use.
 * @param attrs attributes./* w  ww  . j a v a 2  s  . co m*/
 * @param parentView parent
 * @param key key
 * @param value value
 * @param constraintDescription constraints
 * @param readonly if <code>false</code>, the item is disabled for editing.
 */
public GDateView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String key, String value,
        String constraintDescription, boolean readonly) {
    super(fragment.getActivity(), attrs);

    Context context = fragment.getActivity();

    LinearLayout textLayout = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    textLayout.setLayoutParams(layoutParams);
    textLayout.setOrientation(LinearLayout.VERTICAL);
    parentView.addView(textLayout);

    TextView textView = new TextView(context);
    textView.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    textView.setPadding(2, 2, 2, 2);
    textView.setText(key.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
    textView.setTextColor(context.getResources().getColor(R.color.formcolor));
    textLayout.addView(textView);

    button = new Button(context);
    button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    button.setPadding(15, 5, 15, 5);

    final SimpleDateFormat dateFormatter = TimeUtilities.INSTANCE.DATEONLY_FORMATTER;
    if (value == null || value.length() == 0) {
        String dateStr = dateFormatter.format(new Date());
        button.setText(dateStr);
    } else {
        button.setText(value);
    }
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String dateStr = button.getText().toString();
            Date date = null;
            try {
                date = dateFormatter.parse(dateStr);
            } catch (ParseException e) {
                // fallback on current date
                date = new Date();
            }
            final Calendar c = Calendar.getInstance();
            c.setTime(date);
            int year = c.get(Calendar.YEAR);
            int month = c.get(Calendar.MONTH);
            int day = c.get(Calendar.DAY_OF_MONTH);

            FormDatePickerFragment newFragment = new FormDatePickerFragment(year, month, day, button);
            newFragment.show(fragment.getFragmentManager(), "datePicker");
        }
    });
    button.setEnabled(!readonly);

    textLayout.addView(button);
}

From source file:mobisocial.musubi.objects.FileObj.java

@Override
public View createView(Context context, ViewGroup frame) {
    LinearLayout container = new LinearLayout(context);
    container.setLayoutParams(CommonLayouts.FULL_WIDTH);
    container.setOrientation(LinearLayout.HORIZONTAL);
    container.setGravity(Gravity.CENTER);

    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    TextView valueTV = new TextView(context);

    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.BOTTOM | Gravity.LEFT);
    valueTV.setPadding(4, 0, 0, 0);/*from w ww.  j a v a  2s  .  c  om*/

    container.addView(imageView);
    container.addView(valueTV);
    return container;
}

From source file:br.org.funcate.dynamicforms.views.GTimeView.java

/**
 * @param fragment the fragment./*  w w  w .  java2s.  c  o  m*/
 * @param attrs attributes.
 * @param parentView parent
 * @param label label
 * @param value value
 * @param constraintDescription constraints
 * @param readonly if <code>false</code>, the item is disabled for editing.
 */
public GTimeView(final Fragment fragment, AttributeSet attrs, LinearLayout parentView, String label,
        String value, String constraintDescription, boolean readonly) {
    super(fragment.getActivity(), attrs);

    final Context context = fragment.getActivity();

    LinearLayout textLayout = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    textLayout.setLayoutParams(layoutParams);
    textLayout.setOrientation(LinearLayout.VERTICAL);
    parentView.addView(textLayout);

    TextView textView = new TextView(context);
    textView.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    textView.setPadding(2, 2, 2, 2);
    textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
    textView.setTextColor(context.getResources().getColor(R.color.formcolor));
    textLayout.addView(textView);

    button = new Button(context);
    button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    button.setPadding(15, 5, 15, 5);

    final SimpleDateFormat timeFormatter = TimeUtilities.INSTANCE.TIMEONLY_FORMATTER;
    if (value == null || value.length() == 0) {
        String dateStr = timeFormatter.format(new Date());
        button.setText(dateStr);
    } else {
        button.setText(value);
    }
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String dateStr = button.getText().toString();
            Date date = null;
            try {
                date = timeFormatter.parse(dateStr);
            } catch (ParseException e) {
                //GPLog.error(this, null, e);
                Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
                // fallback on current date
                date = new Date();
            }
            final Calendar c = Calendar.getInstance();
            c.setTime(date);
            int hourOfDay = c.get(Calendar.HOUR_OF_DAY);
            int minute = c.get(Calendar.MINUTE);

            FormTimePickerFragment newFragment = new FormTimePickerFragment();
            newFragment.setAttributes(hourOfDay, minute, true, button);
            //newFragment.show(fragment.getFragmentManager(), "timePicker");
        }
    });
    button.setEnabled(!readonly);

    textLayout.addView(button);
}