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:eu.geopaparazzi.core.maptools.FeaturePageAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final Feature feature = featuresList.get(position);

    int bgColor = Compat.getColor(context, eu.geopaparazzi.library.R.color.formbgcolor);
    int textColor = Compat.getColor(context, eu.geopaparazzi.library.R.color.formcolor);

    ScrollView scrollView = new ScrollView(context);
    ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);//from   w  w  w. j  av a2 s.c  o  m
    scrollLayoutParams.setMargins(10, 10, 10, 10);
    scrollView.setLayoutParams(scrollLayoutParams);
    scrollView.setBackgroundColor(bgColor);

    LinearLayout linearLayoutView = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    int margin = 10;
    layoutParams.setMargins(margin, margin, margin, margin);
    linearLayoutView.setLayoutParams(layoutParams);
    linearLayoutView.setOrientation(LinearLayout.VERTICAL);
    int padding = 10;
    linearLayoutView.setPadding(padding, padding, padding, padding);
    scrollView.addView(linearLayoutView);

    List<String> attributeNames = feature.getAttributeNames();
    List<String> attributeValues = feature.getAttributeValuesStrings();
    List<String> attributeTypes = feature.getAttributeTypes();
    for (int i = 0; i < attributeNames.size(); i++) {
        final String name = attributeNames.get(i);
        String value = attributeValues.get(i);
        String typeString = attributeTypes.get(i);
        EDataType type = EDataType.getType4Name(typeString);

        TextView textView = new TextView(context);
        textView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        textView.setPadding(padding, padding, padding, padding);
        textView.setText(name);
        textView.setTextColor(textColor);
        // textView.setTextAppearance(context, android.R.style.TextAppearance_Medium);

        linearLayoutView.addView(textView);

        final TextView editView = getEditView(feature, name, type, value);
        LinearLayout.LayoutParams editViewParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        editViewParams.setMargins(margin, 0, margin, 0);
        editView.setLayoutParams(editViewParams);
        editView.setPadding(padding * 2, padding, padding * 2, padding);
        editView.setFocusable(!isReadOnly);

        if (isReadOnly) {
            editView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    String text = editView.getText().toString();
                    FeatureUtilities.viewIfApplicable(v.getContext(), text);
                    return false;
                }
            });
        }
        linearLayoutView.addView(editView);
    }

    /*
     * add also area and length
     */
    if (feature.getOriginalArea() > -1) {
        TextView areaTextView = new TextView(context);
        areaTextView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        areaTextView.setPadding(padding, padding, padding, padding);
        areaTextView.setText(context.getString(eu.geopaparazzi.core.R.string.area_colon)
                + areaLengthFormatter.format(feature.getOriginalArea()));
        areaTextView.setTextColor(textColor);
        TextView lengthTextView = new TextView(context);
        lengthTextView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        lengthTextView.setPadding(padding, padding, padding, padding);
        lengthTextView.setText(context.getString(eu.geopaparazzi.core.R.string.length_colon)
                + areaLengthFormatter.format(feature.getOriginalLength()));
        lengthTextView.setTextColor(textColor);
        linearLayoutView.addView(areaTextView);
        linearLayoutView.addView(lengthTextView);
    }
    container.addView(scrollView);

    return scrollView;
}

From source file:au.com.wallaceit.reddinator.SimpleTabsWidget.java

private void insertTab(int index, String text) {

    TabClickListener clickListener = new TabClickListener(index);
    LinearLayout tabContainer = (LinearLayout) inflater.inflate(R.layout.tab, tabWidget, false);
    tabContainer.setOnClickListener(clickListener);

    TextView tabText = (TextView) tabContainer.findViewById(R.id.tab_text);
    tabText.setText(text);//from   w ww .  ja v a 2  s  . c o m
    tabText.setTextColor(colors[0]);
    tabItems.add(tabText);

    LinearLayout indicator = (LinearLayout) tabContainer.findViewById(R.id.tab_indicator);
    indicator.setBackgroundColor(colors[1]);
    indicatorItems.add(indicator);

    tabContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1));
    tabWidget.addView(tabContainer);
}

From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java

private View handleBuses(final int position, @NonNull final ViewGroup parent) {
    final LayoutInflater vi = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View convertView = vi.inflate(R.layout.list_nearby, parent, false);

    // Bus/*from   w ww. j  ava  2  s  .  co m*/
    final int index = position - stations.size();
    final BusStop busStop = busStops.get(index);

    final ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(
            ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_directions_bus_white_24dp));

    final TextView routeView = (TextView) convertView.findViewById(R.id.station_name);
    routeView.setText(busStop.getName());

    final LinearLayout resultLayout = (LinearLayout) convertView.findViewById(R.id.nearby_results);

    final Map<String, List<BusArrival>> arrivalsForStop = busArrivals.get(busStop.getId(), new HashMap<>());

    Stream.of(arrivalsForStop.entrySet()).forEach(entry -> {
        final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        final RelativeLayout insideLayout = new RelativeLayout(context);
        insideLayout.setLayoutParams(leftParam);
        insideLayout.setPadding(line1PaddingColor * 2, stopsPaddingTop, 0, 0);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            insideLayout.setBackground(ContextCompat.getDrawable(parent.getContext(), R.drawable.any_selector));
        }

        final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
        int lineId = Util.generateViewId();
        lineIndication.setId(lineId);

        final RelativeLayout.LayoutParams stopParam = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        stopParam.addRule(RelativeLayout.RIGHT_OF, lineId);
        stopParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

        final LinearLayout stopLayout = new LinearLayout(context);
        stopLayout.setOrientation(LinearLayout.VERTICAL);
        stopLayout.setLayoutParams(stopParam);
        int stopId = Util.generateViewId();
        stopLayout.setId(stopId);

        final RelativeLayout.LayoutParams boundParam = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        boundParam.addRule(RelativeLayout.RIGHT_OF, stopId);

        final LinearLayout boundLayout = new LinearLayout(context);
        boundLayout.setOrientation(LinearLayout.HORIZONTAL);

        final String direction = entry.getKey();
        final List<BusArrival> busArrivals = entry.getValue();
        final String routeId = busArrivals.get(0).getRouteId();

        final TextView bound = new TextView(context);
        final String routeIdText = routeId + " (" + direction + "): ";
        bound.setText(routeIdText);
        bound.setTextColor(ContextCompat.getColor(context, R.color.grey_5));
        boundLayout.addView(bound);

        Stream.of(busArrivals).forEach(busArrival -> {
            final TextView timeView = new TextView(context);
            final String timeLeftDueDelay = busArrival.getTimeLeftDueDelay() + " ";
            timeView.setText(timeLeftDueDelay);
            timeView.setTextColor(ContextCompat.getColor(context, R.color.grey));
            timeView.setLines(1);
            timeView.setEllipsize(TruncateAt.END);
            boundLayout.addView(timeView);
        });

        stopLayout.addView(boundLayout);

        insideLayout.addView(lineIndication);
        insideLayout.addView(stopLayout);
        resultLayout.addView(insideLayout);
    });

    convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, busStop.getId(),
            busStop.getPosition().getLatitude(), busStop.getPosition().getLongitude()));
    return convertView;
}

From source file:uk.ac.horizon.artcodes.activity.ExperienceActivity.java

public void copyExperience(View view) {
    if (getExperience().getCanCopy() != null && !getExperience().getCanCopy().booleanValue()) {
        return;//from ww w .  ja v  a  2s .c o m
    }

    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    final LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    linearLayout.setLayoutParams(layoutParams);
    builder.setTitle(R.string.copy);
    builder.setView(linearLayout);
    final Dialog dialog = builder.create();

    for (final Account account : getServer().getAccounts()) {
        if (!account.canEdit(getUri())) {
            Log.i("copy", "Added " + account.getId());
            AccountItemBinding binding = AccountItemBinding.inflate(getLayoutInflater(), linearLayout, false);
            binding.setAccount(account);
            binding.getRoot().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    final Experience experience = getExperience();
                    if (experience.getId() != null && (experience.getId().startsWith("http://")
                            || experience.getId().startsWith("https://"))) {
                        experience.setOriginalID(experience.getId());
                    }
                    experience.setId(null);
                    experience.setName(getString(R.string.copy_of, experience.getName()));
                    experience.getAvailabilities().clear();
                    account.saveExperience(experience);
                    ExperienceActivity.start(ExperienceActivity.this, experience);
                }
            });
            linearLayout.addView(binding.getRoot());
        }
    }

    dialog.show();
}

From source file:com.appfirst.activities.details.AFServerDetail.java

/**
 * @return/*from w ww  .j a  va2  s.  c om*/
 */
private LinearLayout createInnerContainer() {
    LinearLayout innerContainer = new LinearLayout(this);
    innerContainer.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    innerContainer.setOrientation(LinearLayout.VERTICAL);
    innerContainer.setPadding(5, 0, 5, 5);
    return innerContainer;
}

From source file:bruce.kk.brucetodos.MainActivity.java

/**
 * ???/*from  www  .j a  v  a2s.  com*/
 *
 * @param position
 */
private void modifyItem(final int position) {
    final UnFinishItem item = dataList.get(position);
    LogDetails.d(item);
    LinearLayout linearLayout = new LinearLayout(MainActivity.this);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    linearLayout.setLayoutParams(layoutParams);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setBackgroundColor(getResources().getColor(android.R.color.black));

    final EditText editText = new EditText(MainActivity.this);
    editText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    editText.setTextColor(getResources().getColor(android.R.color.holo_green_light));
    editText.setHint(item.content);
    editText.setHintTextColor(getResources().getColor(android.R.color.holo_orange_dark));

    linearLayout.addView(editText);

    Button btnModify = new Button(MainActivity.this);
    btnModify.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    btnModify.setText("");
    btnModify.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    btnModify.setTextColor(getResources().getColor(android.R.color.holo_blue_bright));
    btnModify.setBackgroundColor(getResources().getColor(android.R.color.black));

    linearLayout.addView(btnModify);

    Button btnDeleteItem = new Button(MainActivity.this);
    btnDeleteItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    btnDeleteItem.setText("");
    btnDeleteItem.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    btnDeleteItem.setTextColor(getResources().getColor(android.R.color.holo_blue_bright));
    btnDeleteItem.setBackgroundColor(getResources().getColor(android.R.color.black));

    linearLayout.addView(btnDeleteItem);

    final PopupWindow popupWindow = new PopupWindow(linearLayout, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setBackgroundDrawable(new BitmapDrawable()); // ?
    popupWindow.setTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.showAtLocation(contentMain, Gravity.CENTER, 0, 0);

    btnModify.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            LogDetails.d(": " + editText.getText().toString());
            if (!TextUtils.isEmpty(editText.getText().toString().trim())) {
                Date date = new Date();
                item.content = editText.getText().toString().trim();
                item.modifyDay = date;
                item.finishDay = null;
                ProgressDialogUtils.showProgressDialog();
                presenter.modifyItem(item);
                dataList.set(position, item);
                refreshData(true);
                popupWindow.dismiss();
            } else {
                Toast.makeText(MainActivity.this, "~", Toast.LENGTH_SHORT).show();
            }
        }
    });
    btnDeleteItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dataList.remove(position);
            presenter.deleteItem(item);
            refreshData(false);
            popupWindow.dismiss();
        }
    });
}

From source file:org.zywx.wbpalmstar.plugin.uexscrawl.PhotoScrawlActivity.java

private void showColorChoosePop() {
    LinearLayout linearLayout = new LinearLayout(this);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    int margin = EUExUtil.dipToPixels(8);
    lp.setMargins(margin / 2, margin, margin / 2, margin);
    linearLayout.setLayoutParams(lp);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    for (int color : colors) {
        linearLayout.addView(getColorImageView(color));
    }//  ww w  .j  av  a  2s.  c  om
    HorizontalScrollView scrollView = new HorizontalScrollView(this);
    LinearLayout.LayoutParams scrollLp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    scrollView.setLayoutParams(scrollLp);
    scrollView.addView(linearLayout);

    int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    scrollView.measure(w, h);
    PopupWindow popupWindow = new PopupWindow(scrollView);
    popupWindow.setBackgroundDrawable(new ColorDrawable());
    popupWindow.setFocusable(true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setWidth(mImageContentLayout.getWidth());
    popupWindow.setHeight(scrollView.getMeasuredHeight());
    popupWindow.showAtLocation(mImageContentLayout, Gravity.BOTTOM, 0,
            mCloseLayout.getHeight() + mBrushLayout.getHeight() + popupWindow.getHeight());

}

From source file:it.iziozi.iziozi.gui.IOBoardFragment.java

private View buildView(boolean editMode) {

    this.homeRows.clear();
    final List<IOSpeakableImageButton> mButtons = new ArrayList<IOSpeakableImageButton>();
    List<IOSpeakableImageButton> configButtons = this.mBoard.getButtons();

    ViewGroup mainView = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.table_main_layout,
            null);/*  ww w.j av a2 s .  com*/

    LinearLayout tableContainer = new LinearLayout(getActivity());
    LinearLayout.LayoutParams mainParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    tableContainer.setLayoutParams(mainParams);
    tableContainer.setOrientation(LinearLayout.VERTICAL);

    for (int i = 0; i < this.mBoard.getRows(); i++) {

        LinearLayout rowLayout = new LinearLayout(getActivity());
        LinearLayout.LayoutParams rowParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.f);
        rowLayout.setLayoutParams(rowParams);
        rowLayout.setOrientation(LinearLayout.HORIZONTAL);
        Random color = new Random();
        rowLayout.setBackgroundColor(Color.WHITE);
        tableContainer.addView(rowLayout);
        this.homeRows.add(rowLayout);
    }

    for (int j = 0; j < this.homeRows.size(); j++) {
        LinearLayout homeRow = this.homeRows.get(j);

        for (int i = 0; i < this.mBoard.getCols(); i++) {
            LinearLayout btnContainer = new LinearLayout(getActivity());
            LinearLayout.LayoutParams btnContainerParams = new LinearLayout.LayoutParams(0,
                    LinearLayout.LayoutParams.MATCH_PARENT, 1.f);
            btnContainer.setLayoutParams(btnContainerParams);
            btnContainer.setOrientation(LinearLayout.VERTICAL);
            btnContainer.setGravity(Gravity.CENTER);

            homeRow.addView(btnContainer);

            final IOSpeakableImageButton imgButton = (configButtons.size() > 0
                    && configButtons.size() > mButtons.size()) ? configButtons.get(mButtons.size())
                            : new IOSpeakableImageButton(getActivity());
            imgButton.setmContext(getActivity());
            imgButton.setShowBorder(IOConfiguration.getShowBorders());
            if (IOGlobalConfiguration.isEditing)
                imgButton.setImageDrawable(getResources().getDrawable(R.drawable.logo_org));
            else
                imgButton.setImageDrawable(null);
            imgButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            imgButton.setBackgroundColor(Color.TRANSPARENT);

            if (imgButton.getmImageFile() != null && imgButton.getmImageFile().length() > 0) {

                if (!new File(imgButton.getmImageFile()).exists()) {
                    if (mAlertDialog == null || !mAlertDialog.isShowing()) {
                        mAlertDialog = new AlertDialog.Builder(getActivity()).setCancelable(true)
                                .setTitle(getString(R.string.image_missing))
                                .setMessage(getString(R.string.image_missing_text))
                                .setNegativeButton(getString(R.string.continue_string), null).create();
                        mAlertDialog.show();
                    }

                    //download image

                    if (isExternalStorageReadable()) {

                        File baseFolder = new File(Environment.getExternalStorageDirectory() + "/"
                                + IOApplication.APPLICATION_FOLDER + "/pictograms");
                        Character pictoChar = imgButton.getmImageFile()
                                .charAt(imgButton.getmImageFile().lastIndexOf("/") + 1);
                        File pictoFolder = new File(baseFolder + "/" + pictoChar + "/");

                        if (isExternalStorageWritable()) {

                            pictoFolder.mkdirs();

                            //download it

                            AsyncHttpClient client = new AsyncHttpClient();
                            client.get(imgButton.getmUrl(),
                                    new FileAsyncHttpResponseHandler(new File(imgButton.getmImageFile())) {
                                        @Override
                                        public void onFailure(int statusCode, Header[] headers,
                                                Throwable throwable, File file) {
                                            Toast.makeText(getActivity(),
                                                    getString(R.string.download_error) + file.toString(),
                                                    Toast.LENGTH_LONG).show();
                                        }

                                        @Override
                                        public void onSuccess(int statusCode, Header[] headers,
                                                File downloadedFile) {

                                            if (new File(imgButton.getmImageFile()).exists()) {
                                                imgButton.setImageBitmap(
                                                        BitmapFactory.decodeFile(imgButton.getmImageFile()));
                                            } else {
                                                Toast.makeText(getActivity(),
                                                        getString(R.string.image_save_error),
                                                        Toast.LENGTH_SHORT).show();
                                            }
                                        }
                                    });
                        } else {

                            Toast.makeText(getActivity(), getString(R.string.image_save_error),
                                    Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Toast.makeText(getActivity(), getString(R.string.image_save_error), Toast.LENGTH_SHORT)
                                .show();
                    }

                } else
                    imgButton.setImageBitmap(BitmapFactory.decodeFile(imgButton.getmImageFile()));
            }

            ViewGroup parent = (ViewGroup) imgButton.getParent();

            if (parent != null)
                parent.removeAllViews();

            btnContainer.addView(imgButton);

            mButtons.add(imgButton);

            imgButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    int index = mButtons.indexOf(v);
                    if (mListener != null)
                        mListener.tapOnSpeakableButton(mButtons.get(index), mBoardLevel);
                }
            });
        }
    }

    this.mBoard.setButtons(mButtons.size() > configButtons.size() ? mButtons : configButtons);

    return tableContainer;
}

From source file:com.rainmakerlabs.bleepsample.BleepService.java

public void imgShow(Bitmap bitmap, String strImgMsg) {
    MainActivity.adlib.put(strImgMsg, bitmap);
    Log.d("Portal", "Added an image. Size is now " + MainActivity.adlib.size());
    Log.i("Portal", "Image added for key " + strImgMsg);

    if (MainActivity.myGallery == null)
        return;//www  .  j  a v a2  s .  c o  m

    if (MainActivity.gal_size < MainActivity.adlib.size()) { //new image has been added and the layout is initialized
        LinearLayout superLL = (LinearLayout) MainActivity.myGallery.getParent().getParent();

        if (MainActivity.gal_size < 1) {
            ImageView imgSplash = (ImageView) superLL.findViewById(R.id.imgSplash);
            imgSplash.setVisibility(View.INVISIBLE);
        }

        LinearLayout layout = new LinearLayout(getApplicationContext());
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        layout.setGravity(Gravity.CENTER);

        ImageView imageview = new ImageView(getApplicationContext());
        imageview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1000));
        imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageview.setImageBitmap(bitmap);

        //Add a button to go with it
        Button btnBuy = new Button(getApplicationContext());
        LinearLayout.LayoutParams btnParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        btnParams.setMargins(-10, -10, -10, -10);
        btnBuy.setLayoutParams(btnParams);
        btnBuy.setText("Buy Now (" + strImgMsg + ")");
        btnBuy.setBackgroundColor(MainActivity.getDominantColor(bitmap));
        btnBuy.setTextColor(Color.WHITE);

        btnBuy.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent newActivity = new Intent(getApplicationContext(), WebActivity.class);
                newActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                newActivity.putExtra("URL", "https://portal-battlehack.herokuapp.com/");
                startActivity(newActivity);
            }
        });

        layout.addView(imageview);
        layout.addView(btnBuy);
        MainActivity.myGallery.addView(layout);
        MainActivity.gal_size++;
    }

}

From source file:com.gome.haoyuangong.views.MyViewPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;// w  w  w  .  ja  v  a  2  s  .c  om
    tabView.setTag("tavView");
    tabView.setId(index);
    //      tabView.setFocusable(true);
    //      tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    //tabView.setPadding(pointSize, 0, pointSize, 0);
    tabView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tabView.setMaxLines(1);
    tabView.setGravity(Gravity.CENTER);
    XmlPullParser xrp = getResources().getXml(R.drawable.tab_button);
    try {
        ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);
        tabView.setTextColor(csl);
    } catch (Exception e) {

    }

    if (iconResId != 0) {
        //tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }

    FrameLayout.LayoutParams tabTvL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabView.setLayoutParams(tabTvL);

    //measureView(tabView);

    LinearLayout layoutWraper1 = new LinearLayout(getContext());
    LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1);
    layoutWraper1.setLayoutParams(lp1);
    layoutWraper1.setGravity(Gravity.CENTER);
    layoutWraper1.setFocusable(true);
    layoutWraper1.setOnClickListener(mTabClickListener);
    layoutWraper1.setPadding(0, 0, 0, 0);
    layoutWraper1.setBackgroundResource(R.drawable.tab_btn_red);

    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setTag("framelayout");
    //      FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(tabView.getMeasuredWidth() + padding, tabView.getMeasuredHeight()+ (int)(padding * 1.5));
    FrameLayout.LayoutParams fl2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    //      frameLayout.setPadding(padding, padding, padding, padding);
    frameLayout.setLayoutParams(fl2);
    //      frameLayout.addView(tabView);

    View hasNew = new View(getContext());
    FrameLayout.LayoutParams hasNewL = new FrameLayout.LayoutParams(pointSize, pointSize);
    hasNew.setLayoutParams(hasNewL);
    hasNewL.gravity = Gravity.TOP | Gravity.RIGHT;
    hasNew.setBackgroundResource(R.drawable.shape_circle);

    FrameLayout tabTvframe = new FrameLayout(getContext());
    FrameLayout.LayoutParams tabTvframeL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tabTvframeL.gravity = Gravity.CENTER;
    tabTvframe.setLayoutParams(tabTvframeL);
    tabTvframe.addView(tabView);
    tabTvframe.addView(hasNew);
    hasNew.setVisibility(View.GONE);

    frameLayout.addView(tabTvframe);

    layoutWraper1.addView(frameLayout);

    tabView.setTagView(hasNew);

    mTabLayout.addView(layoutWraper1, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}