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

public PagerSlidingTabStrip(Context context, AttributeSet attrs) {
    super(context, attrs);

    setFillViewport(true);//  w w w .  ja  va  2 s.  c o  m
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = context.getResources().getColor(R.color.yongchao_blue);//a.getColor(R.styleable.PagerSlidingTabStrip_indicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_underlineColor, underlineColor);
    underlineLengthPercentage = a.getFloat(R.styleable.PagerSlidingTabStrip_underlineLongPercentage,
            underlineLengthPercentage);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_dividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_indicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_underlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_dividerPadding, dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_tabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_tabBackground, tabBackgroundResId);
    //shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_shouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_scrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_textAllCaps, textAllCaps);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.STROKE);
    rectPaint.setStrokeWidth(indicatorHeight);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    underLinePaint = new Paint();
    underLinePaint.setColor(COLOR_UNDER_LINE);
    underLinePaint.setStrokeWidth(2);
    underLinePaint.setStyle(Style.STROKE);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.astuetz.PagerSlidingTabStripMenu.java

public PagerSlidingTabStripMenu(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // setFillViewport(true);
    setWillNotDraw(false);//  w w w .j ava2s .  c  om

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tabsContainer.setGravity(Gravity.CENTER);
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    mTabPaddingTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabPaddingTop, dm);
    mTabPaddingBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabPaddingBottom, dm);
    mTabDrawablePadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabDrawablePadding, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    mIconPostion = IconPosition
            .fromValue(a.getInteger(R.styleable.PagerSlidingTabStrip_pstsIconPosition, mIconPostion.value));
    mTabPaddingTop = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStrip_pstsTabPaddingTop,
            mTabPaddingTop);
    mTabPaddingBottom = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStrip_pstsTabPaddingBottom,
            mTabPaddingBottom);
    mTabDrawablePadding = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStrip_pstsTabDrawablePadding,
            mTabDrawablePadding);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.egoclean.testpregnancy.util.ActivityHelper.java

/**
 * Adds an action button to the compatibility action bar, using menu information from a
 * {@link android.view.MenuItem}. If the menu item ID is <code>menu_refresh</code>, the menu item's state
 * can be changed to show a loading spinner using
 * {@link ActivityHelper#setRefreshActionButtonCompatState(boolean)}.
 *///  w  w  w.  j a va  2 s .c  o  m
private View addActionButtonCompatFromMenuItem(final MenuItem item) {
    final ViewGroup actionBar = getActionBarCompat();
    if (actionBar == null) {
        return null;
    }

    // Create the separator
    ImageView separator = new ImageView(mActivity, null, R.attr.actionbarCompatSeparatorStyle);
    separator.setLayoutParams(new ViewGroup.LayoutParams(2, ViewGroup.LayoutParams.FILL_PARENT));

    // Create the button
    ImageButton actionButton = new ImageButton(mActivity, null, R.attr.actionbarCompatButtonStyle);
    actionButton.setId(item.getItemId());
    actionButton.setLayoutParams(new ViewGroup.LayoutParams(
            (int) mActivity.getResources().getDimension(R.dimen.actionbar_compat_height),
            ViewGroup.LayoutParams.FILL_PARENT));
    actionButton.setImageDrawable(item.getIcon());
    actionButton.setScaleType(ImageView.ScaleType.CENTER);
    actionButton.setContentDescription(item.getTitle());
    actionButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            mActivity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, item);
        }
    });

    actionBar.addView(separator);
    actionBar.addView(actionButton);

    if (item.getItemId() == R.id.menu_refresh) {
        // Refresh buttons should be stateful, and allow for indeterminate progress indicators,
        // so add those.
        int buttonWidth = mActivity.getResources().getDimensionPixelSize(R.dimen.actionbar_compat_height);
        int buttonWidthDiv3 = buttonWidth / 3;
        ProgressBar indicator = new ProgressBar(mActivity, null, R.attr.actionbarCompatProgressIndicatorStyle);
        LinearLayout.LayoutParams indicatorLayoutParams = new LinearLayout.LayoutParams(buttonWidthDiv3,
                buttonWidthDiv3);
        indicatorLayoutParams.setMargins(buttonWidthDiv3, buttonWidthDiv3, buttonWidth - 2 * buttonWidthDiv3,
                0);
        indicator.setLayoutParams(indicatorLayoutParams);
        indicator.setVisibility(View.GONE);
        indicator.setId(R.id.menu_refresh_progress);
        actionBar.addView(indicator);
    }

    return actionButton;
}

From source file:ca.xef6.firecamp.ProfilePictureSampleFragment.java

private void updateProfilePicForCustomSizeIncrement(int i) {
    if (pictureSizeType != ProfilePictureView.CUSTOM) {
        return;/*from  ww w  . j  a  v  a2s.  c om*/
    }

    // This will ensure a minimum size of 51x68 and will scale the image at
    // a ratio of 3:4 (w:h) as the SeekBar is moved.
    //
    // Completely arbitrary
    //
    // NOTE: The numbers are in dips.
    float width = (i * 21) + 51;
    float height = (i * 28) + 68;

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            (int) (width * getResources().getDisplayMetrics().density),
            (int) (height * getResources().getDisplayMetrics().density));
    profilePic.setLayoutParams(params);
}

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

@SuppressLint("NewApi")
private void loadElements(long id) {
    viewComments = (ViewGroup) findViewById(R.id.commentContainer);
    viewComments.removeAllViews();//w  w w.ja v a 2  s .  com
    viewLikes = (ViewGroup) findViewById(R.id.likesLayout);
    loading = LayoutInflater.from(context).inflate(R.layout.loadingfootercomments, null);
    viewComments.addView(loading, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    installString = getString(R.string.install);
    viewLikesButton = (ViewGroup) findViewById(R.id.ratings);
    ((TextView) viewLikes.findViewById(R.id.likes)).setText(context.getString(R.string.loading_likes));
    ((TextView) viewLikes.findViewById(R.id.dislikes)).setText("");

    findViewById(R.id.downloading_icon).setVisibility(View.GONE);
    findViewById(R.id.downloading_name).setVisibility(View.GONE);
    findViewById(R.id.download_progress).setVisibility(View.GONE);
    ProgressBar progress = (ProgressBar) findViewById(R.id.downloading_progress);
    progress.setIndeterminate(true);
    Bundle b = new Bundle();
    b.putLong("_id", id);

    //      findViewById(R.id.inst_version).setVisibility(View.VISIBLE);
    getSupportLoaderManager().restartLoader(20, b, new LoaderCallbacks<ViewApk>() {

        @Override
        public Loader<ViewApk> onCreateLoader(int arg0, final Bundle arg1) {
            pd.show();
            pd.setMessage(getString(R.string.please_wait));
            pd.setCancelable(false);
            return new ViewApkLoader(ApkInfo.this) {

                @Override
                public ViewApk loadInBackground() {
                    return db.getApk(arg1.getLong("_id"), category);
                }
            };

        }

        @Override
        public void onLoadFinished(Loader<ViewApk> arg0, ViewApk arg1) {
            //                AdView adView = (AdView)findViewById(R.id.adView);
            //                adView.loadAd(new AdRequest());

            mAdView = (MoPubView) findViewById(R.id.adview);
            mAdView.setAdUnitId(ApplicationAptoide.ADUNITID); // Enter your Ad Unit ID from www.mopub.com
            mAdView.loadAd();
            pd.dismiss();
            viewApk = arg1;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    loadDescription();
                }
            }).start();

            mainObbUrl = viewApk.getMainObbUrl();
            mainObbMd5 = viewApk.getMainObbMd5();
            mainObbName = viewApk.getMainObbFileName();
            mainObbSize = viewApk.getMainObbFileSize();

            patchObbUrl = viewApk.getPatchObbUrl();
            patchObbMd5 = viewApk.getPatchObbMd5();
            patchObbName = viewApk.getPatchObbFileName();
            patchObbSize = viewApk.getPatchObbFileSize();

            if (viewApk.getLikes() != -1) {
                setLikes(viewApk.getLikes() + "", viewApk.getDislikes() + "");
            }

            if (viewApk.getComments().size() > 0) {
                setComments(viewApk.getComments());
                loading.setVisibility(View.GONE);
            }

            loadScreenshots();

            //viewApk.getWebservicePath

            int installedVercode = db.getInstalledAppVercode(viewApk.getApkid());

            if (installedVercode <= viewApk.getVercode() && installedVercode != 0) {
                findViewById(R.id.inst_version).setVisibility(View.VISIBLE);
                ((TextView) findViewById(R.id.inst_version)).setText(getString(R.string.installed_version)
                        + ": " + db.getInstalledAppVername(viewApk.getApkid()));
                if (installedVercode < viewApk.getVercode() && !getIntent().hasExtra("installed")) {
                    installString = getString(R.string.update);
                } else if (getIntent().hasExtra("installed")) {
                    installString = getString(R.string.open);
                }
                ((Button) findViewById(R.id.btinstall)).setText(installString);

            } else if (installedVercode > viewApk.getVercode()) {
                if (getIntent().hasExtra("installed")) {
                    installString = getString(R.string.open);
                } else {
                    installString = getString(R.string.install);

                }
                ((Button) findViewById(R.id.btinstall)).setText(installString);

                findViewById(R.id.inst_version).setVisibility(View.GONE);
            }

            if (installedVercode == viewApk.getVercode()) {
                if (getIntent().hasExtra("installed")) {
                    installString = getString(R.string.open);
                } else {
                    installString = getString(R.string.install);
                }
                ((Button) findViewById(R.id.btinstall)).setText(installString);
                findViewById(R.id.inst_version).setVisibility(View.GONE);
            }

            repo_string = viewApk.getRepoName();
            checkDownloadStatus();
            webservicespath = viewApk.getWebservicesPath();

            try {
                ((RatingBar) findViewById(R.id.ratingbar)).setRating(Float.parseFloat(viewApk.getRating()));
                ((RatingBar) findViewById(R.id.ratingbar)).setIsIndicator(true);
            } catch (Exception e) {
                ((RatingBar) findViewById(R.id.ratingbar)).setRating(0);
                ((RatingBar) findViewById(R.id.ratingbar)).setIsIndicator(true);
            }
            ((TextView) findViewById(R.id.app_store)).setText(getString(R.string.store) + ": " + repo_string);
            ((TextView) findViewById(R.id.versionInfo)).setText(getString(R.string.clear_dwn_title) + ": "
                    + viewApk.getDownloads() + " " + getString(R.string.size) + ": "
                    + withSuffix((Long.parseLong(viewApk.getSize()) * 1024 + mainObbSize + patchObbSize)));
            ((TextView) findViewById(R.id.version_label))
                    .setText(getString(R.string.version) + " " + viewApk.getVername());
            ((TextView) findViewById(R.id.app_name)).setText(viewApk.getName());
            //            ImageLoader imageLoader = ImageLoader.getInstance(context);
            //            imageLoader.DisplayImage(viewApk.getIcon(),(ImageView) findViewById(R.id.app_icon), context, (viewApk.getApkid()+"|"+viewApk.getVercode()));
            DisplayImageOptions options = new DisplayImageOptions.Builder()
                    .displayer(new FadeInBitmapDisplayer(1000))
                    .showStubImage(android.R.drawable.sym_def_app_icon).resetViewBeforeLoading().cacheInMemory()
                    .cacheOnDisc().build();
            ImageLoader.getInstance().displayImage(viewApk.getIcon(), (ImageView) findViewById(R.id.app_icon),
                    options, null, (viewApk.getApkid() + "|" + viewApk.getVercode()));

            new GetApkInfo().execute();

            /*Comments comments = new Comments(context,webservicespath);
            comments.getComments(repo_string, viewApk.getApkid(),viewApk.getVername(),(LinearLayout) findViewById(R.id.commentContainer), false);*/
            likes = new Likes(context, webservicespath);
            /*likes.getLikes(repo_string, viewApk.getApkid(), viewApk.getVername(),(ViewGroup) findViewById(R.id.likesLayout),(ViewGroup) findViewById(R.id.ratings));*/

            ItemBasedApks items = new ItemBasedApks(context, viewApk);
            items.getItems((LinearLayout) findViewById(R.id.itembasedapks_container),
                    (LinearLayout) findViewById(R.id.itembasedapks_maincontainer),
                    (TextView) findViewById(R.id.itembasedapks_label));

            if (!spinnerInstanciated) {
                loadApkVersions();
            }
            setClickListeners();

            //Malware badges
            loadMalwareBadges();
            if (Build.VERSION.SDK_INT >= 11) {
                invalidateOptionsMenu();
            }

            //                if(!getIntent().hasExtra("installed")){
            //                    new checkPaymentTask().execute();
            //                }

        }

        private void loadMalwareBadges() {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        loadMalware(viewApk.getMalwareStatus());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();

        }

        @Override
        public void onLoaderReset(Loader<ViewApk> arg0) {

        }
    });

    //

    //

    //      Button serch_mrkt = (Button)findViewById(R.id.btmarket);
    //      serch_mrkt.setOnClickListener(new OnClickListener() {
    //
    //         public void onClick(View v) {

    //         }
    //
    //      });

    //

    //
    //

}

From source file:ru.orangesoftware.financisto.activity.CategorySelector.java

public void createAttributesLayout(LinearLayout layout) {
    attributesLayout = new LinearLayout(activity);
    attributesLayout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(attributesLayout, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
}

From source file:org.solovyev.android.messenger.BaseListFragment.java

@Override
public ViewGroup onCreateView(LayoutInflater inflater, ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    Log.d(tag, "onCreateView");
    final LinearLayout root = new LinearLayout(themeContext);
    root.setOrientation(VERTICAL);// w w  w .jav  a 2  s.com

    if (listViewFilter != null) {
        final View filterView = listViewFilter.createView(savedInstanceState);
        root.addView(filterView, new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
    }

    final View listViewParent = createListView();

    final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1f);
    params.gravity = CENTER_VERTICAL;
    root.addView(listViewParent, params);

    tryUpdateActionBar();

    multiPaneManager.onCreatePane(getActivity(), container, root);

    initViewStates(savedInstanceState);

    return root;
}

From source file:net.willwebberley.gowertides.ui.DayFragment.java

private void setSurfInfo() {
    double x = dayView.getApplicationContext().getResources().getDisplayMetrics().density;

    LinearLayout surf = (LinearLayout) layoutView.findViewById(R.id.surf); // Get the linear layout to add the surf details to
    // Set some basic layout params (last arg is weight - set to 0.2)
    LinearLayout.LayoutParams param = new LinearLayout.LayoutParams((int) (x * 100),
            LinearLayout.LayoutParams.MATCH_PARENT);
    // Calculate the pixel density (in dpi)...

    // ... and use this to set the horizontal margins of the views to be added to the LinearLayout (i.e. 5dpi left and right)
    param.setMargins((int) (5 * x), 0, (int) (5 * x), 0);

    // Finally remove all views in there already, before repopulating with the layoutparams specified above.
    surf.removeAllViews();//from  ww w .jav a  2s  . c o m
    ArrayList<Surf> reports = day.getSurfReports();
    for (int i = 0; i < reports.size(); i++) {
        SurfFragment si = new SurfFragment(dayView.getApplicationContext(), reports.get(i));
        surf.addView(si.getView(), param);
    }
}

From source file:net.willwebberley.gowertides.ui.DayFragment.java

private void setTideTableInfo() {
    LinearLayout tides = (LinearLayout) layoutView.findViewById(R.id.tides); // Get the linear layout to add the surf details to
    LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    // Calculate the pixel density (in dpi)...
    double x = dayView.getApplicationContext().getResources().getDisplayMetrics().density;
    // ... and use this to set the horizontal margins of the views to be added to the LinearLayout (i.e. 5dpi left and right)
    param.setMargins((int) (5 * x), 0, (int) (5 * x), 0);

    // Finally remove all views in there already, before repopulating with the layoutparams specified above.
    tides.removeAllViews();/*from w  w w  .j  av a 2s.  c o  m*/
    ArrayList<Tide> forecasts = day.getTides();
    for (int i = 0; i < forecasts.size(); i++) {
        TideFragment ti = new TideFragment(dayView.getApplicationContext(), forecasts.get(i), day);
        tides.addView(ti.getView(), param);
    }
}

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

private void addRedDotTab(final int position, String title, int resId) {
    LinearLayout tabLayout = new LinearLayout(getContext());
    tabLayout.setOrientation(LinearLayout.HORIZONTAL);
    tabLayout.setGravity(Gravity.CENTER);
    TextView tab = new TextView(getContext());
    tab.setText(title);//w ww. j a  v a  2s . co  m
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);

    tab.setSingleLine();
    tab.setTextColor(getResources().getColorStateList(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, 0);
    ImageView tabImg = new ImageView(getContext());
    LinearLayout.LayoutParams tabImgParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    tabImgParams.setMargins(DeviceUtils.dip2px(getContext(), 5), DeviceUtils.dip2px(getContext(), 10), 0, 0);
    tabImgParams.gravity = Gravity.TOP;
    tabImg.setLayoutParams(tabImgParams);

    tabLayout.addView(tabImg, 1);
    tabsContainer.addView(tabLayout);
}