Example usage for android.widget ImageView setLayoutParams

List of usage examples for android.widget ImageView setLayoutParams

Introduction

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

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

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  . j  a  v  a  2s .c  o 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:com.vista.zoonv1.CategoriaFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.categoriafragment, container, false);
    LinearLayout layout = (LinearLayout) rootView.findViewById(R.id.categoria_linerlayout);
    // ///////////////////////////////////////////

    // LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
    // LayoutParams.MATCH_PARENT);

    // FrameLayout fl = new FrameLayout(getActivity());
    // fl.setLayoutParams(params);

    // final int margin = (int) TypedValue.applyDimension(
    // TypedValue.COMPLEX_UNIT_DIP, 1, getResources()
    // .getDisplayMetrics());

    // TextView v = new TextView(getActivity());
    // params.setMargins(margin, margin, margin, margin);
    // v.setLayoutParams(params);
    // v.setLayoutParams(params);
    // v.setGravity(Gravity.CENTER);
    // v.setBackgroundResource(R.drawable.background_card);
    // v.setText("Aqui poner una listta de item:    Nro " + (position + 1));
    // ScrollView scrollView = new ScrollView(getActivity());
    int min = 0;/*from  w ww. j a  v  a  2  s  .c  o m*/
    int max = 10;
    Random r = new Random();

    for (int i = 0; i < _IMG_SUBCAT.length; i++) {
        ImageView imageView = new ImageView(getActivity());
        int i1 = r.nextInt(max - min + 1) + min;
        if (i1 % 2 == 0) {

            imageView.setImageResource(_IMG_SUBCAT[i]);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(60, 60);
            params.setMargins(5, 20, 5, 3);
            imageView.setLayoutParams(params);
            layout.addView(imageView);

        }
    }

    // fl.addView(scrollView);
    return rootView;
}

From source file:info.papdt.blacklight.ui.common.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*w w w.  j ava2s  .  co  m*/
 */
protected View createDefaultTabView(Context context) {
    View v;
    if (mIconAdapter == null) {
        TextView textView = new TextView(context);
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
        textView.setTypeface(Typeface.DEFAULT_BOLD);
        textView.setAllCaps(true);
        textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        int padding = (int) (TAB_TEXT_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
        textView.setPadding(padding, padding, padding, padding);

        v = textView;
    } else {
        ImageView imgView = new TintImageView(context);
        imgView.setScaleType(ImageView.ScaleType.FIT_XY);
        imgView.setLayoutParams(new LinearLayout.LayoutParams(mTabIconSize, mTabIconSize));

        v = imgView;
    }

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    if (v instanceof ImageView) {
        v.setBackgroundResource(outValue.resourceId);
        int padding = (int) (TAB_ICON_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
        v.setPadding(padding, padding, padding, padding);
    }

    return v;
}

From source file:com.dreamspace.superman.UI.View.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from ww  w .ja  va2 s. c o m*/
 */
protected View createDefaultTabView(Context context) {
    View v;
    if (mIconAdapter == null) {
        TextView textView = new TextView(context);
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
        textView.setTypeface(Typeface.DEFAULT);
        textView.setAllCaps(true);
        textView.setTextColor(getStartColor());
        if (fillTheWidth) {
            textView.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1));
        } else {
            textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));

        }
        ;

        v = textView;
    } else {
        ImageView imgView = new TintImageView(context);
        imgView.setScaleType(ImageView.ScaleType.FIT_XY);
        imgView.setLayoutParams(new LinearLayout.LayoutParams(mTabIconSize, mTabIconSize));
        v = imgView;
    }

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    v.setBackgroundResource(outValue.resourceId);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    v.setPadding(padding, padding, padding, padding);

    return v;
}

From source file:id.ridon.keude.views.AppListAdapter.java

private void layoutIcon(ImageView icon, boolean compact) {
    int size = (int) mContext.getResources()
            .getDimension((compact ? R.dimen.applist_icon_compact_size : R.dimen.applist_icon_normal_size));

    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) icon.getLayoutParams();

    params.height = size;/* ww  w .  ja  va 2  s  .  co m*/
    params.width = size;

    icon.setLayoutParams(params);
}

From source file:org.alfresco.mobile.android.application.fragments.node.favorite.FavoritesFragment.java

@Override
protected void prepareEmptyView(View ev, ImageView emptyImageView, TextView firstEmptyMessage,
        TextView secondEmptyMessage) {//from w  w  w  .  j a  v a  2  s.c o m
    emptyImageView.setImageResource(R.drawable.ic_empty_favorites);
    emptyImageView.setLayoutParams(DisplayUtils.resizeLayout(getActivity(), 275, 275));
    firstEmptyMessage.setText(R.string.favorites_empty_title);
    secondEmptyMessage.setVisibility(View.VISIBLE);
    secondEmptyMessage.setText(R.string.favorites_empty_description);
}

From source file:hongik.android.project.best.StoreActivity.java

public void drawPage() throws Exception {
    String query = "func=storereview" + "&license=" + license;

    DBConnector conn = new DBConnector(query);
    conn.start();/*from w w w .j a  v  a 2 s. co m*/
    conn.join();

    JSONObject jsonResult = conn.getResult();
    boolean result = jsonResult.getBoolean("result");
    if (!result)
        return;

    final JSONObject store = jsonResult.getJSONArray("store").getJSONObject(0);

    JSONArray menu = null;
    if (!jsonResult.isNull("menu"))
        menu = jsonResult.getJSONArray("menu");

    JSONArray review = null;
    if (!jsonResult.isNull("review"))
        review = jsonResult.getJSONArray("review");

    //Draw Store Information
    Lat = Double.parseDouble(store.getString("LAT"));
    Lng = Double.parseDouble(store.getString("LNG"));
    sname = store.getString("SNAME");
    ((TextViewPlus) findViewById(R.id.store_storename)).setText(sname);
    ((TextViewPlus) findViewById(R.id.store_address)).setText(store.getString("ADDR"));
    ImageLoader imgLoader = new ImageLoader(store.getString("IMG"));
    imgLoader.start();

    try {
        imgLoader.join();
        Bitmap storeImg = imgLoader.getBitmap();
        ((ImageView) findViewById(R.id.store_image)).setImageBitmap(storeImg);
    } catch (InterruptedException e) {
        Toast.makeText(this, "Can not bring " + license + "store's image", Toast.LENGTH_SHORT).show();
        Log.e("StoreInfo", "Can not bring " + license + "store's image");
    }

    //Draw Menu Table
    if (menu != null) {
        TableRow motive = (TableRow) menuTable.getChildAt(1);

        for (int i = 0; i < menu.length(); i++) {
            JSONObject json = menu.getJSONObject(i);

            TableRow tbRow = new TableRow(this);
            TextViewPlus[] tbCols = new TextViewPlus[3];

            final String[] elements = new String[2];
            elements[0] = json.getString("ITEM#");
            elements[1] = json.getString("PRICE");

            imgLoader = new ImageLoader(json.getString("IMG"));
            imgLoader.start();
            imgLoader.join();

            ImageView img = new ImageView(this);
            Bitmap bitmap = imgLoader.getBitmap();
            img.setImageBitmap(bitmap);
            img.setLayoutParams(motive.getChildAt(0).getLayoutParams());
            img.setScaleType(ImageView.ScaleType.FIT_XY);
            img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent storeIntent = new Intent(originActivity, MenuActivity.class);
                    storeIntent.putExtra("LICENSE", license);
                    storeIntent.putExtra("MENU", elements[0]);
                    startActivity(storeIntent);
                }
            });

            tbRow.addView(img);

            for (int j = 0; j < 2; j++) {
                tbCols[j] = new TextViewPlus(this);
                tbCols[j].setText(elements[j]);
                tbCols[j].setLayoutParams(motive.getChildAt(j + 1).getLayoutParams());
                tbCols[j].setGravity(Gravity.CENTER);
                tbCols[j].setTypeface(Typeface.createFromAsset(tbCols[j].getContext().getAssets(),
                        "InterparkGothicBold.ttf"));
                tbCols[j].setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent storeIntent = new Intent(originActivity, MenuActivity.class);
                        storeIntent.putExtra("LICENSE", license);
                        storeIntent.putExtra("MENU", elements[0]);
                        startActivity(storeIntent);
                    }
                });

                Log.i("StoreMenu", "COL" + j + ":" + elements[j]);
                tbRow.addView(tbCols[j]);
            }
            menuTable.addView(tbRow);
        }
    }
    menuTable.removeViewAt(1);

    //Draw Review Table
    if (review != null) {
        TableRow motive = (TableRow) reviewTable.getChildAt(1);

        int rowCnt = 5;
        if (review.length() < 5)
            rowCnt = review.length();
        for (int i = 0; i < rowCnt; i++) {
            JSONObject json = review.getJSONObject(i);

            final String[] elements = new String[4];
            elements[0] = Double.parseDouble(json.getString("GRADE")) + "";
            elements[1] = json.getString("NOTE");
            elements[2] = json.getString("CID#");
            elements[3] = json.getString("DAY");

            TableRow tbRow = new TableRow(this);
            TextViewPlus[] tbCols = new TextViewPlus[4];

            if (elements[1].length() > 14)
                elements[1] = elements[1].substring(0, 14) + "...";

            for (int j = 0; j < 4; j++) {
                tbCols[j] = new TextViewPlus(this);
                tbCols[j].setText(elements[j]);
                tbCols[j].setLayoutParams(motive.getChildAt(j).getLayoutParams());
                tbCols[j].setGravity(Gravity.CENTER);
                tbCols[j].setTypeface(Typeface.createFromAsset(tbCols[j].getContext().getAssets(),
                        "InterparkGothicBold.ttf"));
                tbCols[j].setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent reviewIntent = new Intent(originActivity, ReviewDetailActivity.class);
                        reviewIntent.putExtra("ACCESS", "STORE");
                        reviewIntent.putExtra("CID", elements[2]);
                        reviewIntent.putExtra("LICENSE", license);
                        Log.i("StoreReview", "StartActivity");
                        startActivity(reviewIntent);
                    }
                });

                Log.i("StoreMenu", "COL" + j + ":" + elements[j]);
                tbRow.addView(tbCols[j]);
            }
            reviewTable.addView(tbRow);
        }
    }
    reviewTable.removeViewAt(1);

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.store_map);
    mapFragment.getMapAsync(this);
}

From source file:com.common.android.lib.controls.view.indicator.IconPageIndicator.java

public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();/* www . j a va  2  s.  c  o  m*/
    IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter();
    int count = iconAdapter.getCount();
    for (int i = 0; i < count; i++) {
        ImageView view = new ImageView(getContext());
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.setMargins(15, 0, 0, 0);
        view.setImageResource(iconAdapter.getIconResId(i));
        view.setLayoutParams(lp);
        mIconsLayout.addView(view);
    }
    if (mSelectedIndex > count) {
        mSelectedIndex = count - 1;
    }
    setCurrentItem(mSelectedIndex);
    requestLayout();
}

From source file:org.onebusaway.android.ui.TutorialFragment.java

private void updatePagerIndicator(int position, int size) {
    LinearLayout linear = (LinearLayout) getActivity().findViewById(R.id.pager_indicator);
    linear.removeAllViewsInLayout();/*from w  w w  .j  a v  a 2 s.c  om*/

    for (int i = 0; i < size; i++) {
        ImageView iw = new ImageView(getActivity());
        if (position == i) {
            iw.setImageResource(R.drawable.pager_dot_hover);
        } else {
            iw.setImageResource(R.drawable.pager_dot);
        }

        iw.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) iw.getLayoutParams();
        params.setMargins(5, 0, 0, 0);
        iw.setLayoutParams(params);

        linear.addView(iw);
    }
}

From source file:org.musicmod.android.app.MusicBrowserActivity.java

@Override
public View makeView() {
    ImageView i = new ImageView(this);
    i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
    return i;/*www.  j av a2  s. co  m*/
}