Example usage for android.widget LinearLayout.LayoutParams LinearLayout.LayoutParams

List of usage examples for android.widget LinearLayout.LayoutParams LinearLayout.LayoutParams

Introduction

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

Prototype

public LayoutParams(int width, int height) 

Source Link

Usage

From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java

private void addWarningTab(final int position, String title, int resId) {
    LinearLayout tabLayout = new LinearLayout(getContext());
    tabLayout.setOrientation(LinearLayout.HORIZONTAL);
    tabLayout.setGravity(Gravity.CENTER);

    ImageView tabImg = new ImageView(getContext());
    int width = DimenUtils.dp2px(getContext(), 18);
    LinearLayout.LayoutParams tabImgParams = new LinearLayout.LayoutParams(width, width);
    tabImgParams.setMargins(0, 0, DimenUtils.dp2px(getContext(), 10), 0);
    tabImgParams.gravity = Gravity.CENTER;
    tabImg.setLayoutParams(tabImgParams);
    if (resId != -1) {
        tabImg.setBackgroundResource(resId);
        tabImg.setVisibility(View.VISIBLE);
    } else {//from w w  w.ja v  a 2  s  .co  m
        tabImg.setVisibility(View.GONE);
    }
    tabLayout.addView(tabImg, 0);

    TextView tab = new TextView(getContext());
    tab.setText(title);
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setTextColor(getResources().getColorStateList(
            mTextChangeable ? R.color.pst_tab_changeable_text_selector : R.color.pst_tab_text_selector));
    tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f);
    tabLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mOnPageClickedLisener) {
                mOnPageClickedLisener.onPageClicked(position);
            }
            pager.setCurrentItem(position);
        }
    });
    tabLayout.addView(tab, 1);

    tabsContainer.addView(tabLayout);
}

From source file:cm.aptoide.pt.MainActivity.java

private void loadRecommended() {

    if (Login.isLoggedIn(mContext)) {
        ((TextView) featuredView.findViewById(R.id.recommended_text)).setVisibility(View.GONE);
    } else {//from  w w  w . j a  va2s . c  om
        ((TextView) featuredView.findViewById(R.id.recommended_text)).setVisibility(View.VISIBLE);
    }

    new Thread(new Runnable() {

        private ArrayList<HashMap<String, String>> valuesRecommended;

        public void run() {
            loadUIRecommendedApps();
            File f = null;
            try {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                NetworkUtils utils = new NetworkUtils();
                BufferedInputStream bis = new BufferedInputStream(
                        utils.getInputStream("http://webservices.aptoide.com/webservices/listUserBasedApks/"
                                + Login.getToken(mContext) + "/10/xml", null, null, mContext),
                        8 * 1024);
                f = File.createTempFile("abc", "abc");
                OutputStream out = new FileOutputStream(f);
                byte buf[] = new byte[1024];
                int len;
                while ((len = bis.read(buf)) > 0)
                    out.write(buf, 0, len);
                out.close();
                bis.close();
                String hash = Md5Handler.md5Calc(f);
                ViewApk parent_apk = new ViewApk();
                parent_apk.setApkid("recommended");
                if (!hash.equals(db.getItemBasedApksHash(parent_apk.getApkid()))) {
                    // Database.database.beginTransaction();
                    db.deleteItemBasedApks(parent_apk);
                    sp.parse(f, new HandlerItemBased(parent_apk));
                    db.insertItemBasedApkHash(hash, parent_apk.getApkid());
                    // Database.database.setTransactionSuccessful();
                    // Database.database.endTransaction();
                    loadUIRecommendedApps();
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

            if (f != null)
                f.delete();

        }

        private void loadUIRecommendedApps() {

            valuesRecommended = db.getItemBasedApksRecommended("recommended");

            runOnUiThread(new Runnable() {

                public void run() {

                    LinearLayout ll = (LinearLayout) featuredView.findViewById(R.id.recommended_container);
                    ll.removeAllViews();
                    LinearLayout llAlso = new LinearLayout(MainActivity.this);
                    llAlso.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT));
                    llAlso.setOrientation(LinearLayout.HORIZONTAL);
                    if (valuesRecommended.isEmpty()) {
                        if (Login.isLoggedIn(mContext)) {
                            TextView tv = new TextView(mContext);
                            tv.setText(R.string.no_recommended_apps);
                            tv.setTextAppearance(mContext, android.R.attr.textAppearanceMedium);
                            tv.setPadding(10, 10, 10, 10);
                            ll.addView(tv);
                        }
                    } else {

                        for (int i = 0; i != valuesRecommended.size(); i++) {
                            LinearLayout txtSamItem = (LinearLayout) getLayoutInflater()
                                    .inflate(R.layout.row_grid_item, null);
                            ((TextView) txtSamItem.findViewById(R.id.name))
                                    .setText(valuesRecommended.get(i).get("name"));
                            ImageLoader.getInstance().displayImage(valuesRecommended.get(i).get("icon"),
                                    (ImageView) txtSamItem.findViewById(R.id.icon));
                            float stars = 0f;
                            try {
                                stars = Float.parseFloat(valuesRecommended.get(i).get("rating"));
                            } catch (Exception e) {
                                stars = 0f;
                            }
                            ((RatingBar) txtSamItem.findViewById(R.id.rating)).setIsIndicator(true);
                            ((RatingBar) txtSamItem.findViewById(R.id.rating)).setRating(stars);
                            txtSamItem.setPadding(10, 0, 0, 0);
                            // ((TextView)
                            // txtSamItem.findViewById(R.id.version))
                            // .setText(getString(R.string.version) +" "+
                            // valuesRecommended.get(i).get("vername"));
                            ((TextView) txtSamItem.findViewById(R.id.downloads))
                                    .setText("(" + valuesRecommended.get(i).get("downloads") + " "
                                            + getString(R.string.downloads) + ")");
                            txtSamItem.setTag(valuesRecommended.get(i).get("_id"));
                            txtSamItem.setLayoutParams(new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.MATCH_PARENT, 100, 1));
                            // txtSamItem.setOnClickListener(featuredListener);
                            txtSamItem.setOnClickListener(new OnClickListener() {

                                @Override
                                public void onClick(View arg0) {
                                    Intent i = new Intent(MainActivity.this, ApkInfo.class);
                                    long id = Long.parseLong((String) arg0.getTag());
                                    i.putExtra("_id", id);
                                    i.putExtra("top", true);
                                    i.putExtra("category", Category.ITEMBASED.ordinal());
                                    startActivity(i);
                                }
                            });

                            txtSamItem.measure(0, 0);

                            if (i % 2 == 0) {
                                ll.addView(llAlso);

                                llAlso = new LinearLayout(MainActivity.this);
                                llAlso.setLayoutParams(new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.MATCH_PARENT, 100));
                                llAlso.setOrientation(LinearLayout.HORIZONTAL);
                                llAlso.addView(txtSamItem);
                            } else {
                                llAlso.addView(txtSamItem);
                            }
                        }

                        ll.addView(llAlso);
                    }
                }
            });
        }
    }).start();

}

From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED) {
        return;/*w  ww  . ja  v a 2 s  .  c o m*/
    }

    if (checkedTabWidths) {
        return;
    }

    int childWidth = 0;
    for (int i = 0; i < tabCount; i++) {
        childWidth += tabsContainer.getChildAt(i).getMeasuredWidth();
    }

    int myWidth = getMeasuredWidth();
    if (childWidth > 0 && myWidth > 0) {

        if (mAliquots) {
            for (int i = 0; i < tabCount; i++) {
                tabsContainer.getChildAt(i).setLayoutParams(expandedTabLayoutParams);
            }

        } else {

            //  TAB ?? defaultTabLayoutParams
            // ???? TAB
            if (childWidth <= myWidth) {
                int extras = myWidth - childWidth;
                if (extras > 0) {
                    int extrasPadding = extras / tabCount;
                    tabPadding += extrasPadding / 2;

                    for (int i = 0; i < tabCount; i++) {
                        LinearLayout.LayoutParams itemLayout = new LinearLayout.LayoutParams(
                                tabsContainer.getChildAt(i).getMeasuredWidth() + extrasPadding,
                                LayoutParams.MATCH_PARENT);
                        tabsContainer.getChildAt(i).setLayoutParams(itemLayout);
                    }
                }
            } else {
                for (int i = 0; i < tabCount; i++) {
                    tabsContainer.getChildAt(i).setLayoutParams(defaultTabLayoutParams);
                }
            }

        }

        checkedTabWidths = true;
    }
}

From source file:com.purdue.CampusFeed.Activities.ContactDetailFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

    // If this fragment was cleared while the query was running
    // eg. from from a call like setContact(uri) then don't do
    // anything.// w  w w . j  ava 2 s.c  o  m
    if (mContactUri == null) {
        return;
    }

    switch (loader.getId()) {
    case ContactDetailQuery.QUERY_ID:
        // Moves to the first row in the Cursor
        if (data.moveToFirst()) {
            // For the contact details query, fetches the contact display name.
            // ContactDetailQuery.DISPLAY_NAME maps to the appropriate display
            // name field based on OS version.
            final String contactName = data.getString(ContactDetailQuery.DISPLAY_NAME);
            if (mIsTwoPaneLayout && mContactName != null) {
                // In the two pane layout, there is a dedicated TextView
                // that holds the contact name.
                mContactName.setText(contactName);
            } else {
                // In the single pane layout, sets the activity title
                // to the contact name. On HC+ this will be set as
                // the ActionBar title text.
                getActivity().setTitle(contactName);
            }
        }
        break;
    case ContactAddressQuery.QUERY_ID:
        // This query loads the contact address details. More than
        // one contact address is possible, so move each one to a
        // LinearLayout in a Scrollview so multiple addresses can
        // be scrolled by the user.

        // Each LinearLayout has the same LayoutParams so this can
        // be created once and used for each address.
        /*
        final LinearLayout.LayoutParams layoutParams =
                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
                
        // Clears out the details layout first in case the details
        // layout has addresses from a previous data load still
        // added as children.
        mDetailsLayout.removeAllViews();
                
        // Loops through all the rows in the Cursor
        if (data.moveToFirst()) {
            do {
                // Builds the address layout
                final LinearLayout layout = buildAddressLayout(
                        data.getInt(ContactAddressQuery.TYPE),
                        data.getString(ContactAddressQuery.LABEL),
                        data.getString(ContactAddressQuery.ADDRESS));
                // Adds the new address layout to the details layout
                mDetailsLayout.addView(layout, layoutParams);
            } while (data.moveToNext());
        } else {
            // If nothing found, adds an empty address layout
            mDetailsLayout.addView(buildEmptyAddressLayout(), layoutParams);
        }*/
        break;
    case ContactPhoneQuery.QUERY_ID:

        ContactDetailFragment.contactPhoneNumbers.clear();

        final LinearLayout.LayoutParams layoutParameters = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        // Clears out the details layout first in case the details
        // layout has addresses from a previous data load still
        // added as children.
        mDetailsLayout.removeAllViews();

        // Loops through all the rows in the Cursor
        if (data.moveToFirst()) {
            do {
                // Builds the address layout
                String contactPhoneNumber = data.getString(ContactPhoneQuery.PHONE_NUMBER);
                ContactDetailFragment.contactPhoneNumbers.add(contactPhoneNumber);

                final LinearLayout layout = buildAddressLayout(contactPhoneNumber);
                // Adds the new address layout to the details layout
                mDetailsLayout.addView(layout, layoutParameters);

                ImageButton button = (ImageButton) mDetailsLayout
                        .findViewById(R.id.contact_detail_item_sms_button);
                button.setVisibility(View.VISIBLE);

            } while (data.moveToNext());

        } else {
            // If nothing found, adds an empty address layout
            mDetailsLayout.addView(buildEmptyAddressLayout(), layoutParameters);

            ImageButton button = (ImageButton) mDetailsLayout.findViewById(R.id.contact_detail_item_sms_button);
            button.setVisibility(View.INVISIBLE);
        }

        break;
    }
}

From source file:cm.aptoide.pt.MainActivity.java

private void loadUItopapps() {
    ((ToggleButton) featuredView.findViewById(R.id.toggleButton1)).setOnCheckedChangeListener(null);
    Cursor c = db.getFeaturedTopApps();

    values = new ArrayList<HashMap<String, String>>();
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        HashMap<String, String> item = new HashMap<String, String>();
        item.put("name", c.getString(1));
        item.put("icon", db.getIconsPath(0, Category.TOPFEATURED) + c.getString(4));
        item.put("rating", c.getString(5));
        item.put("id", c.getString(0));
        item.put("apkid", c.getString(7));
        item.put("vercode", c.getString(8));
        item.put("vername", c.getString(2));
        item.put("downloads", c.getString(6));
        if (values.size() == 26) {
            break;
        }/*from  w ww  . j a  va2 s  . com*/
        values.add(item);
    }
    c.close();

    runOnUiThread(new Runnable() {

        public void run() {

            LinearLayout ll = (LinearLayout) featuredView.findViewById(R.id.container);
            ll.removeAllViews();
            LinearLayout llAlso = new LinearLayout(MainActivity.this);
            llAlso.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            llAlso.setOrientation(LinearLayout.HORIZONTAL);
            for (int i = 0; i != values.size(); i++) {
                LinearLayout txtSamItem = (LinearLayout) getLayoutInflater().inflate(R.layout.row_grid_item,
                        null);
                ((TextView) txtSamItem.findViewById(R.id.name)).setText(values.get(i).get("name"));
                // ((TextView) txtSamItem.findViewById(R.id.version))
                // .setText(getString(R.string.version) +" "+
                // values.get(i).get("vername"));
                ((TextView) txtSamItem.findViewById(R.id.downloads)).setText(
                        "(" + values.get(i).get("downloads") + " " + getString(R.string.downloads) + ")");
                String hashCode = (values.get(i).get("apkid") + "|" + values.get(i).get("vercode")) + "";
                cm.aptoide.com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(
                        values.get(i).get("icon"), (ImageView) txtSamItem.findViewById(R.id.icon), hashCode);

                // imageLoader.DisplayImage(-1, values.get(i).get("icon"),
                // (ImageView) txtSamItem.findViewById(R.id.icon),
                // mContext);
                float stars = 0f;
                try {
                    stars = Float.parseFloat(values.get(i).get("rating"));
                } catch (Exception e) {
                    stars = 0f;
                }
                ((RatingBar) txtSamItem.findViewById(R.id.rating)).setRating(stars);
                ((RatingBar) txtSamItem.findViewById(R.id.rating)).setIsIndicator(true);
                txtSamItem.setPadding(10, 0, 0, 0);
                txtSamItem.setTag(values.get(i).get("id"));
                txtSamItem.setLayoutParams(
                        new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 100, 1));
                // txtSamItem.setOnClickListener(featuredListener);
                txtSamItem.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        Intent i = new Intent(MainActivity.this, ApkInfo.class);
                        long id = Long.parseLong((String) arg0.getTag());
                        i.putExtra("_id", id);
                        i.putExtra("top", true);
                        i.putExtra("category", Category.TOPFEATURED.ordinal());
                        startActivity(i);
                    }
                });

                txtSamItem.measure(0, 0);

                if (i % 2 == 0) {
                    ll.addView(llAlso);

                    llAlso = new LinearLayout(MainActivity.this);
                    llAlso.setLayoutParams(
                            new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 100));
                    llAlso.setOrientation(LinearLayout.HORIZONTAL);
                    llAlso.addView(txtSamItem);
                } else {
                    llAlso.addView(txtSamItem);
                }
            }

            ll.addView(llAlso);
            SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mContext);
            // System.out.println(sPref.getString("app_rating",
            // "All").equals(
            // "Mature"));
            ((ToggleButton) featuredView.findViewById(R.id.toggleButton1))
                    .setChecked(!sPref.getBoolean("matureChkBox", false));
            ((ToggleButton) featuredView.findViewById(R.id.toggleButton1))
                    .setOnCheckedChangeListener(adultCheckedListener);
        }
    });
}

From source file:com.max.library.view.TabLayout.java

private LinearLayout.LayoutParams createLayoutParamsForTabs() {
    final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);/*w  w w .ja  v  a  2  s .  c om*/
    updateTabViewLayoutParams(lp);
    return lp;
}

From source file:com.max.library.view.TabLayout.java

private LinearLayout.LayoutParams createLayoutParamsForTabs(float weight) {
    final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);/*from  www . ja v a 2  s.c  om*/
    updateTabViewLayoutParams(lp, weight);
    return lp;
}

From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java

private void showHighlightEditDialog(final HighLight highLight) {
    final AlertDialog.Builder editalert = new AlertDialog.Builder(context);

    editalert.setTitle(R.string.text_note);
    final EditText input = new EditText(context);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    input.setLayoutParams(lp);/* ww  w  . j  ava 2  s.  c om*/
    editalert.setView(input);
    input.setText(highLight.getTextNote());

    editalert.setPositiveButton(R.string.save_note, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            highLight.setTextNote(input.getText().toString());
            bookView.update();
            highlightManager.saveHighLights();
        }
    });
    editalert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });

    editalert.setNeutralButton(R.string.clear_note, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            highLight.setTextNote(null);
            bookView.update();
            highlightManager.saveHighLights();
        }
    });

    editalert.show();
}

From source file:net.nightwhistler.pageturner.fragment.ReadingFragment.java

private void showHighlightEditDialog(final HighLight highLight) {
    final AlertDialog.Builder editalert = new AlertDialog.Builder(context);

    editalert.setTitle(R.string.text_note);
    final EditText input = new EditText(context);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    input.setLayoutParams(lp);//from   w  ww .j  a v a2s  .c o  m
    editalert.setView(input);
    input.setText(highLight.getTextNote());

    editalert.setPositiveButton(R.string.save_note, (dialog, which) -> {
        highLight.setTextNote(input.getText().toString());
        bookView.update();
        highlightManager.saveHighLights();
    });

    editalert.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
    });

    editalert.setNeutralButton(R.string.clear_note, (dialog, which) -> {
        highLight.setTextNote(null);
        bookView.update();
        highlightManager.saveHighLights();
    });

    editalert.show();
}

From source file:com.javielinux.tweettopics2.TweetTopicsActivity.java

public void showOptionsColumns(int positionX, int index, boolean action_bar_opened) {

    int x = positionX - (layoutOptionsColumns.getWidth() / 2);
    if (x < 0)
        x = 0;//from www  . j a va  2 s. co  m
    if (x > widthScreen - layoutOptionsColumns.getWidth())
        x = widthScreen - layoutOptionsColumns.getWidth();
    int y = -1;

    if (action_bar_opened)
        y = (int) getResources().getDimension(R.dimen.actionbar_columns_height) - Utils.dip2px(this, 20);
    else
        y = (int) getResources().getDimension(R.dimen.actionbar_height) - Utils.dip2px(this, 20);

    int xCenterView = x;

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.setMargins(x, y, 0, 0);
    layoutOptionsColumns.setLayoutParams(params);

    layoutMainOptionsColumns.setVisibility(View.VISIBLE);

    btnOptionsColumnsMain.setTag(index);
    btnOptionsColumnsEdit.setTag(index);

    ObjectAnimator translationX = ObjectAnimator.ofFloat(layoutOptionsColumns, "translationX", xCenterView - x,
            0f);
    translationX.setDuration(150);
    ObjectAnimator scaleX = ObjectAnimator.ofFloat(layoutOptionsColumns, "scaleX", 0f, 1f);
    scaleX.setDuration(150);
    ObjectAnimator scaleY = ObjectAnimator.ofFloat(layoutOptionsColumns, "scaleY", 0f, 1f);
    scaleY.setDuration(150);
    ObjectAnimator fadeAnim = ObjectAnimator.ofFloat(layoutOptionsColumns, "alpha", 0f, 1f);
    fadeAnim.setDuration(150);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(translationX, scaleX, scaleY, fadeAnim);
    animatorSet.start();

}