Example usage for android.widget RelativeLayout BELOW

List of usage examples for android.widget RelativeLayout BELOW

Introduction

In this page you can find the example usage for android.widget RelativeLayout BELOW.

Prototype

int BELOW

To view the source code for android.widget RelativeLayout BELOW.

Click Source Link

Document

Rule that aligns a child's top edge with another child's bottom edge.

Usage

From source file:org.odk.collect.android.views.MediaLayout.java

public void setAVT(FormIndex index, String selectionDesignator, TextView text, String audioURI, String imageURI,
        String videoURI, final String bigImageURI) {
    this.selectionDesignator = selectionDesignator;
    this.index = index;
    viewText = text;//from   w w  w. j  a v a2s.  c o  m
    originalText = text.getText();
    viewText.setId(ViewIds.generateViewId());
    this.videoURI = videoURI;

    // Layout configurations for our elements in the relative layout
    RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams audioParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams videoParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);

    // First set up the audio button
    if (audioURI != null) {
        // An audio file is specified
        audioButton = new AudioButton(getContext(), this.index, this.selectionDesignator, audioURI, player);
        audioButton.setPadding(22, 12, 22, 12);
        audioButton.setBackgroundColor(Color.LTGRAY);
        audioButton.setOnClickListener(this);
        audioButton.setId(ViewIds.generateViewId()); // random ID to be used by the
        // relative layout.
    } else {
        // No audio file specified, so ignore.
    }

    // Then set up the video button
    if (videoURI != null) {
        // An video file is specified
        videoButton = new AppCompatImageButton(getContext());
        Bitmap b = BitmapFactory.decodeResource(getContext().getResources(), android.R.drawable.ic_media_play);
        videoButton.setImageBitmap(b);
        videoButton.setPadding(22, 12, 22, 12);
        videoButton.setBackgroundColor(Color.LTGRAY);
        videoButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "onClick",
                        "playVideoPrompt" + MediaLayout.this.selectionDesignator, MediaLayout.this.index);
                MediaLayout.this.playVideo();
            }

        });
        videoButton.setId(ViewIds.generateViewId());
    } else {
        // No video file specified, so ignore.
    }

    // Now set up the image view
    String errorMsg = null;
    final int imageId = ViewIds.generateViewId();
    if (imageURI != null) {
        try {
            String imageFilename = ReferenceManager.instance().DeriveReference(imageURI).getLocalURI();
            final File imageFile = new File(imageFilename);
            if (imageFile.exists()) {
                DisplayMetrics metrics = context.getResources().getDisplayMetrics();
                int screenWidth = metrics.widthPixels;
                int screenHeight = metrics.heightPixels;
                Bitmap b = FileUtils.getBitmapScaledToDisplay(imageFile, screenHeight, screenWidth);
                if (b != null) {
                    imageView = new ImageView(getContext());
                    imageView.setPadding(2, 2, 2, 2);
                    imageView.setImageBitmap(b);
                    imageView.setId(imageId);

                    imageView.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (bigImageURI != null) {
                                Collect.getInstance().getActivityLogger().logInstanceAction(this, "onClick",
                                        "showImagePromptBigImage" + MediaLayout.this.selectionDesignator,
                                        MediaLayout.this.index);

                                try {
                                    File bigImage = new File(ReferenceManager.instance()
                                            .DeriveReference(bigImageURI).getLocalURI());

                                    Intent i = new Intent("android.intent.action.VIEW");
                                    i.setDataAndType(Uri.fromFile(bigImage), "image/*");
                                    getContext().startActivity(i);
                                } catch (InvalidReferenceException e) {
                                    Timber.e(e, "Invalid image reference due to %s ", e.getMessage());
                                } catch (ActivityNotFoundException e) {
                                    Timber.d(e, "No Activity found to handle due to %s", e.getMessage());
                                    ToastUtils.showShortToast(
                                            getContext().getString(R.string.activity_not_found, "view image"));
                                }
                            } else {
                                if (viewText instanceof RadioButton) {
                                    ((RadioButton) viewText).setChecked(true);
                                } else if (viewText instanceof CheckBox) {
                                    CheckBox checkbox = (CheckBox) viewText;
                                    checkbox.setChecked(!checkbox.isChecked());
                                }
                            }
                        }
                    });
                } else {
                    // Loading the image failed, so it's likely a bad file.
                    errorMsg = getContext().getString(R.string.file_invalid, imageFile);
                }
            } else {
                // We should have an image, but the file doesn't exist.
                errorMsg = getContext().getString(R.string.file_missing, imageFile);
            }

            if (errorMsg != null) {
                // errorMsg is only set when an error has occurred
                Timber.e(errorMsg);
                missingImage = new TextView(getContext());
                missingImage.setText(errorMsg);
                missingImage.setPadding(10, 10, 10, 10);
                missingImage.setId(imageId);
            }
        } catch (InvalidReferenceException e) {
            Timber.e(e, "Invalid image reference due to %s ", e.getMessage());
        }
    } else {
        // There's no imageURI listed, so just ignore it.
    }

    // e.g., for TextView that flag will be true
    boolean isNotAMultipleChoiceField = !RadioButton.class.isAssignableFrom(text.getClass())
            && !CheckBox.class.isAssignableFrom(text.getClass());

    // Determine the layout constraints...
    // Assumes LTR, TTB reading bias!
    if (viewText.getText().length() == 0 && (imageView != null || missingImage != null)) {
        // No text; has image. The image is treated as question/choice icon.
        // The Text view may just have a radio button or checkbox. It
        // needs to remain in the layout even though it is blank.
        //
        // The image view, as created above, will dynamically resize and
        // center itself. We want it to resize but left-align itself
        // in the resized area and we want a white background, as otherwise
        // it will show a grey bar to the right of the image icon.
        if (imageView != null) {
            imageView.setScaleType(ScaleType.FIT_START);
        }
        //
        // In this case, we have:
        // Text upper left; image upper, left edge aligned with text right edge;
        // audio upper right; video below audio on right.
        textParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        textParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        if (isNotAMultipleChoiceField) {
            imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
        } else {
            imageParams.addRule(RelativeLayout.RIGHT_OF, viewText.getId());
        }
        imageParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        if (audioButton != null && videoButton == null) {
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            audioParams.setMargins(0, 0, 11, 0);
            imageParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
        } else if (audioButton == null && videoButton != null) {
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            videoParams.setMargins(0, 0, 11, 0);
            imageParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId());
        } else if (audioButton != null && videoButton != null) {
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            audioParams.setMargins(0, 0, 11, 0);
            imageParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            videoParams.addRule(RelativeLayout.BELOW, audioButton.getId());
            videoParams.setMargins(0, 20, 11, 0);
            imageParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId());
        } else {
            // the image will implicitly scale down to fit within parent...
            // no need to bound it by the width of the parent...
            if (!isNotAMultipleChoiceField) {
                imageParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            }
        }
        imageParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    } else {
        // We have a non-blank text label -- image is below the text.
        // In this case, we want the image to be centered...
        if (imageView != null) {
            imageView.setScaleType(ScaleType.FIT_START);
        }
        //
        // Text upper left; audio upper right; video below audio on right.
        // image below text, audio and video buttons; left-aligned with text.
        textParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        textParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        if (audioButton != null && videoButton == null) {
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            audioParams.setMargins(0, 0, 11, 0);
            textParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
        } else if (audioButton == null && videoButton != null) {
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            videoParams.setMargins(0, 0, 11, 0);
            textParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId());
        } else if (audioButton != null && videoButton != null) {
            audioParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            audioParams.setMargins(0, 0, 11, 0);
            textParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
            videoParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            videoParams.setMargins(0, 20, 11, 0);
            videoParams.addRule(RelativeLayout.BELOW, audioButton.getId());
        } else {
            textParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        }

        if (imageView != null || missingImage != null) {
            imageParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            imageParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            if (videoButton != null) {
                imageParams.addRule(RelativeLayout.LEFT_OF, videoButton.getId());
            } else if (audioButton != null) {
                imageParams.addRule(RelativeLayout.LEFT_OF, audioButton.getId());
            }
            imageParams.addRule(RelativeLayout.BELOW, viewText.getId());
        } else {
            textParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        }
    }

    addView(viewText, textParams);
    if (audioButton != null) {
        addView(audioButton, audioParams);
    }
    if (videoButton != null) {
        addView(videoButton, videoParams);
    }
    if (imageView != null) {
        addView(imageView, imageParams);
    } else if (missingImage != null) {
        addView(missingImage, imageParams);
    }
}

From source file:io.jawg.osmcontributor.ui.fragments.MapFragment.java

private void instantiateProgressBar() {
    progressBar = new ButteryProgressBar(getActivity());
    progressBar.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 24));
    RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    p.addRule(RelativeLayout.BELOW, R.id.poi_type_value_wrapper);
    progressBar.setVisibility(View.GONE);
    progressBar.setLayoutParams(p);/*  w w  w. ja va 2 s  .  co m*/
    progressbarWrapper.addView(progressBar);
}

From source file:com.tmall.wireless.tangram.view.BannerView.java

private void bindHeaderView(BaseCell cell) {
    if (cell != null) {
        View header = getViewFromRecycler(cell);
        if (header != null) {
            header.setId(R.id.TANGRAM_BANNER_HEADER_ID);
            RelativeLayout.LayoutParams bodyLp = (LayoutParams) mUltraViewPager.getLayoutParams();
            bodyLp.addRule(RelativeLayout.BELOW, R.id.TANGRAM_BANNER_HEADER_ID);
            // item ?itemView  layoutParams ?? layout ,??? layoutParams
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            lp.topMargin = cell.style.margin[Style.MARGIN_TOP_INDEX];
            lp.leftMargin = cell.style.margin[Style.MARGIN_LEFT_INDEX];
            lp.bottomMargin = cell.style.margin[Style.MARGIN_BOTTOM_INDEX];
            lp.rightMargin = cell.style.margin[Style.MARGIN_RIGHT_INDEX];
            addView(header, lp);//  ww  w .j a  v a  2  s .co  m
        }
    }
}

From source file:fiskinfoo.no.sintef.fiskinfoo.CardViewFragment.java

private TextView generateTextViewWithText(String text, TextView parent) {
    TextView textView = new TextView(getActivity());
    RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    p.addRule(RelativeLayout.BELOW, parent.getId());
    textView.setLayoutParams(p);/*from w  w w  .j av  a2 s . co m*/
    textView.setId(generateRandomId());
    textView.setText(text);
    textView.setPadding(8, 8, 8, 8);
    textView.setTextColor(Color.parseColor("#666666"));
    textView.setTextSize(14);
    return textView;
}

From source file:com.spoiledmilk.ibikecph.LeftMenu.java

@SuppressWarnings("deprecation")
public void updateControls() {
    LOG.d("LeftMenu updateControls");
    if (!IbikeApplication.isUserLogedIn()) {
        favoritesContainer.setBackgroundDrawable(null);
        textFavoriteHint.setTextColor(getHintDisabledTextColor());
        textNewFavorite.setTextColor(Color.rgb(60, 60, 60));
        imgAdd.setImageResource(R.drawable.fav_plus_none);
        favoritesList.setAdapter(null);//from  www  .j  ava  2s  . c  o m
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, Util.dp2px(150));
        favoritesContainerHeight = Util.dp2px(150);
        params.addRule(RelativeLayout.CENTER_HORIZONTAL);
        params.addRule(RelativeLayout.BELOW, favoritesHeaderContainer.getId());
        favoritesContainer.setLayoutParams(params);
        addContainer.setPadding((int) (Util.getScreenWidth() / 7 + Util.dp2px(7)), (int) Util.dp2px(5), 0,
                (int) Util.dp2px(34));
        // getView().findViewById(R.id.imgRightArrow).setVisibility(View.INVISIBLE);
        textFavoriteHint.setVisibility(View.VISIBLE);
        btnEditFavorites.setVisibility(View.INVISIBLE);
        btnEditFavorites.setEnabled(false);
        lastListDivider.setVisibility(View.GONE);
        params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        params.topMargin = Util.dp2px(3);
        // imgAdd.setLayoutParams(params);
        textNewFavorite.setPadding(Util.dp2px(0), 0, 0, Util.dp2px(0));
        params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        params.bottomMargin = Util.getDensity() >= 2 ? Util.dp2px(40) : Util.dp2px(20);
        addContainer.setLayoutParams(params);
        addContainer.setPadding(Util.getDensity() >= 2 ? Util.dp2px(60) : Util.dp2px(40), Util.dp2px(7), 0,
                Util.dp2px(7));
        addContainer.setBackgroundColor(Color.TRANSPARENT);
        addContainer.setClickable(false);
    } else if (favorites == null || favorites.size() == 0) {
        favoritesContainer.setBackgroundResource(R.drawable.add_fav_background_selector);
        addContainer.setBackgroundColor(Color.TRANSPARENT);// addContainer.setBackgroundResource(R.drawable.add_fav_background_selector);
        lastListDivider.setVisibility(View.GONE);
        favoritesList.setVisibility(View.GONE);
        textFavoriteHint.setVisibility(View.VISIBLE);
        // getView().findViewById(R.id.imgRightArrow).setVisibility(View.VISIBLE);
        favoritesContainer.setClickable(true);
        imgAdd.setImageResource(R.drawable.fav_add);
        textFavoriteHint.setTextColor(getHintEnabledTextColor());
        textNewFavorite.setTextColor(getAddFavoriteTextColor());
        btnEditFavorites.setVisibility(View.INVISIBLE);
        btnEditFavorites.setEnabled(false);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, Util.dp2px(150));
        favoritesContainerHeight = Util.dp2px(150);
        params.addRule(RelativeLayout.CENTER_HORIZONTAL);
        params.addRule(RelativeLayout.BELOW, getView().findViewById(R.id.favoritesHeaderContainer).getId());
        favoritesContainer.setLayoutParams(params);
        addContainer.setPadding((int) (Util.getScreenWidth() / 7 + Util.dp2px(7)), (int) Util.dp2px(5), 0,
                (int) Util.dp2px(34));
        params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        params.topMargin = Util.dp2px(3);
        // imgAdd.setLayoutParams(params);
        textNewFavorite.setPadding(0, 0, 0, 0);
        params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        params.addRule(RelativeLayout.CENTER_HORIZONTAL);
        params.bottomMargin = Util.getDensity() >= 2 ? Util.dp2px(40) : Util.dp2px(20);
        addContainer.setLayoutParams(params);
        addContainer.setPadding(Util.getDensity() >= 2 ? Util.dp2px(0) : Util.dp2px(10), Util.dp2px(7), 0,
                Util.dp2px(7));
        addContainer.setClickable(false);
    } else {
        // Loged in, and there is a list of favorites
        favoritesList.clearAnimations();
        favoritesList.setVisibility(View.VISIBLE);
        if (listAdapter != null) {
            ((FavoritesAdapter) listAdapter).setIsEditMode(isEditMode);
            btnEditFavorites.setVisibility(isEditMode ? View.INVISIBLE : View.VISIBLE);
            btnEditFavorites.setEnabled(!isEditMode);
            btnDone.setVisibility(isEditMode ? View.VISIBLE : View.INVISIBLE);
            btnDone.setEnabled(isEditMode);
        }
        textFavoriteHint.setVisibility(View.GONE);
        if (getView() != null) {
            addContainer.setVisibility(isEditMode ? View.GONE : View.VISIBLE);
            // getView().findViewById(R.id.imgRightArrow).setVisibility(View.GONE);
            getView().findViewById(R.id.favoritesContainer).setClickable(false);
            int count = favorites.size();
            int listHeight = count * (menuItemHeight) + Util.dp2px(1) * count;
            int viewHeight = (int) (Util.getScreenHeight() - Util.dp2px(26)); //
            // screen height without the
            // notifications bar
            int avaliableHeight = viewHeight - (menuItemHeight * (getMenuItemsCount() + (isEditMode ? 0 : 1)))
                    - (getMenuItemsCount() * dividerHeight);
            LOG.d("available height = " + avaliableHeight);
            LOG.d("list height = " + listHeight);
            if (listHeight > avaliableHeight) {
                listHeight = avaliableHeight;
            }
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT,
                    (isEditMode ? listHeight : (listHeight + menuItemHeight)));
            favoritesContainerHeight = (isEditMode ? listHeight : (listHeight + menuItemHeight));
            params.addRule(RelativeLayout.CENTER_HORIZONTAL);
            params.addRule(RelativeLayout.BELOW, getView().findViewById(R.id.horizontalDivider1).getId());
            favoritesContainer.setLayoutParams(params);
            params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, listHeight);
            params.addRule(RelativeLayout.CENTER_HORIZONTAL);
            params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            getView().findViewById(R.id.favoritesListContainer).setLayoutParams(params);
            imgAdd.setImageResource(R.drawable.fav_add);
            textFavoriteHint.setTextColor(Color.WHITE);
            textNewFavorite.setTextColor(getAddFavoriteTextColor());
            lastListDivider.setVisibility(
                    (isEditMode || favorites.size() <= getFavoritesVisibleItemCount()) ? View.GONE
                            : View.VISIBLE);
            updateFavoritesContainer();
            addContainer.setPadding((int) Util.dp2px(30), (int) Util.dp2px(0), 0, (int) Util.dp2px(0));
            params = new RelativeLayout.LayoutParams(Util.dp2px(14), Util.dp2px(14));
            params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            params.addRule(RelativeLayout.CENTER_VERTICAL);
            params.bottomMargin = Util.dp2px(0);
            // imgAdd.setLayoutParams(params);
            params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, menuItemHeight);
            params.addRule(RelativeLayout.BELOW, getView().findViewById(R.id.favoritesListContainer).getId());
            if (!isEditMode) {
                addContainer.setLayoutParams(params);
            }
            addContainer.setBackgroundResource(R.drawable.add_fav_background_selector);
            addContainer.setClickable(true);
            textNewFavorite.setPadding(Util.dp2px(4), 0, 0, 0);
            ((FavoritesAdapter) listAdapter).notifyDataSetChanged();
        }
    }

}

From source file:com.nextgis.ngm_clink_monitoring.fragments.MapFragment.java

protected void addMapButtons() {
    Context context = getActivity();

    if (mivZoomIn == null || mivZoomOut == null) {
        mivZoomIn = new ImageView(context);
        mivZoomIn.setImageResource(R.drawable.ic_plus);
        mivZoomIn.setId(ViewUtil.generateViewId());

        mivZoomOut = new ImageView(context);
        mivZoomOut.setImageResource(R.drawable.ic_minus);
        mivZoomOut.setId(ViewUtil.generateViewId());

        mivZoomIn.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                mMapView.zoomIn();/*  ww w.j  a  va  2s . c  o m*/
            }
        });

        mivZoomOut.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                mMapView.zoomOut();
            }
        });
    }

    mButtonsRelativeLayout = (RelativeLayout) mMapRelativeLayout.findViewById(mButtonsRelativeLayoutId);

    if (null == mButtonsRelativeLayout) {
        mButtonsRelativeLayout = new RelativeLayout(context);
        mButtonsRelativeLayout.setId(mButtonsRelativeLayoutId);

        RelativeLayout.LayoutParams paramsButtonIn = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        RelativeLayout.LayoutParams paramsButtonOut = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        RelativeLayout.LayoutParams paramsButtonsRl = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

        paramsButtonIn.setMargins(mMargins + 5, mMargins - 5, mMargins + 5, mMargins + 5);
        paramsButtonOut.setMargins(mMargins + 5, mMargins + 5, mMargins + 5, mMargins - 5);

        paramsButtonOut.addRule(RelativeLayout.BELOW, mivZoomIn.getId());
        paramsButtonsRl.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        paramsButtonsRl.addRule(RelativeLayout.CENTER_IN_PARENT);

        mButtonsRelativeLayout.addView(mivZoomIn, paramsButtonIn);
        mButtonsRelativeLayout.addView(mivZoomOut, paramsButtonOut);
        mMapRelativeLayout.addView(mButtonsRelativeLayout, paramsButtonsRl);
    }

    setZoomInEnabled(mMapView.canZoomIn());
    setZoomOutEnabled(mMapView.canZoomOut());
}

From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from  www .  ja v  a2  s .c om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View mainView = inflater.inflate(R.layout.main, container, false);

    if (mainView != null) {
        ViewTreeObserver vto = mainView.getViewTreeObserver();

        if (vto != null) {
            vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                @Override
                public void onGlobalLayout() {
                    MainFragment.removeOnGlobalLayoutListener(mainView, this);
                    int locationTbEndLocation[] = new int[2];
                    mTbEndLocation.getLocationInWindow(locationTbEndLocation);
                    int locationItinerarySelectionSpinner[] = new int[2];
                    mItinerarySelectionSpinner.getLocationInWindow(locationItinerarySelectionSpinner);
                    int locationBtnHandle[] = new int[2];
                    mBtnHandle.getLocationInWindow(locationBtnHandle);
                    DisplayMetrics metrics = MainFragment.this.getResources().getDisplayMetrics();
                    int windowHeight = metrics.heightPixels;
                    int paddingMargin = MainFragment.this.getResources()
                            .getInteger(R.integer.map_padding_margin);
                    if (mMap != null) {
                        mMap.setPadding(locationBtnHandle[0] + mBtnHandle.getWidth() / 2 + paddingMargin,
                                locationTbEndLocation[1] + mTbEndLocation.getHeight() / 2 + paddingMargin, 0,
                                windowHeight - locationItinerarySelectionSpinner[1] + paddingMargin);
                    }
                }
            });
        } else {
            Log.w(OTPApp.TAG, "Not possible to obtain exact element's positions on screen, some other"
                    + "elements can be misplaced");
        }

        mTbStartLocation = (EditText) mainView.findViewById(R.id.tbStartLocation);
        mTbEndLocation = (EditText) mainView.findViewById(R.id.tbEndLocation);

        mBtnPlanTrip = (ImageButton) mainView.findViewById(R.id.btnPlanTrip);
        mDdlOptimization = (ListView) mainView.findViewById(R.id.spinOptimization);
        mDdlTravelMode = (ListView) mainView.findViewById(R.id.spinTravelMode);

        mBikeTriangleParameters = new RangeSeekBar<Double>(OTPApp.BIKE_PARAMETERS_MIN_VALUE,
                OTPApp.BIKE_PARAMETERS_MAX_VALUE, this.getActivity().getApplicationContext(), R.color.sysRed,
                R.color.sysGreen, R.color.sysBlue, R.drawable.seek_thumb_normal, R.drawable.seek_thumb_pressed);

        // add RangeSeekBar to pre-defined layout
        mBikeTriangleParametersLayout = (ViewGroup) mainView.findViewById(R.id.bikeParametersLayout);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.BELOW, R.id.bikeParametersTags);

        mBikeTriangleParametersLayout.addView(mBikeTriangleParameters, params);

        mBtnMyLocation = (ImageButton) mainView.findViewById(R.id.btnMyLocation);

        mBtnDateDialog = (ImageButton) mainView.findViewById(R.id.btnDateDialog);

        mBtnDisplayDirection = (ImageButton) mainView.findViewById(R.id.btnDisplayDirection);

        mNavigationDrawerLeftPane = (ViewGroup) mainView.findViewById(R.id.navigationDrawerLeftPane);
        mPanelDisplayDirection = mainView.findViewById(R.id.panelDisplayDirection);

        mBtnHandle = (ImageButton) mainView.findViewById(R.id.btnHandle);
        mDrawerLayout = (DrawerLayout) mainView.findViewById(R.id.drawerLayout);

        mTbStartLocation.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        mTbEndLocation.setImeOptions(EditorInfo.IME_ACTION_DONE);
        mTbEndLocation.requestFocus();

        mItinerarySelectionSpinner = (Spinner) mainView.findViewById(R.id.itinerarySelection);

        Log.v(OTPApp.TAG, "finish onStart()");

        if (Build.VERSION.SDK_INT > 11) {
            LayoutTransition l = new LayoutTransition();
            ViewGroup mainButtons = (ViewGroup) mainView.findViewById(R.id.content_frame);
            mainButtons.setLayoutTransition(l);
        }

        return mainView;
    } else {
        Log.e(OTPApp.TAG, "Not possible to obtain main view, UI won't be correctly created");
        return null;
    }
}

From source file:com.tmall.wireless.tangram.view.BannerView.java

private void bindFooterView(BaseCell cell) {
    if (cell != null) {
        View footer = getViewFromRecycler(cell);
        if (footer != null) {
            footer.setId(R.id.TANGRAM_BANNER_FOOTER_ID);
            // item ?itemView  layoutParams ?? layout ,??? layoutParams
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            lp.addRule(RelativeLayout.BELOW, R.id.TANGRAM_BANNER_ID);
            lp.topMargin = cell.style.margin[Style.MARGIN_TOP_INDEX];
            lp.leftMargin = cell.style.margin[Style.MARGIN_LEFT_INDEX];
            lp.bottomMargin = cell.style.margin[Style.MARGIN_BOTTOM_INDEX];
            lp.rightMargin = cell.style.margin[Style.MARGIN_RIGHT_INDEX];
            addView(footer, lp);/*from  www  .  jav a  2 s  . c om*/
        }
    }
}

From source file:org.odk.collect.android.views.MediaLayout.java

/**
 * This adds a divider at the bottom of this layout. Used to separate fields in lists.
 *//*from  w  w  w  . j  av a2s . com*/
public void addDivider(ImageView v) {
    RelativeLayout.LayoutParams dividerParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    if (imageView != null) {
        dividerParams.addRule(RelativeLayout.BELOW, imageView.getId());
    } else if (missingImage != null) {
        dividerParams.addRule(RelativeLayout.BELOW, missingImage.getId());
    } else if (videoButton != null) {
        dividerParams.addRule(RelativeLayout.BELOW, videoButton.getId());
    } else if (audioButton != null) {
        dividerParams.addRule(RelativeLayout.BELOW, audioButton.getId());
    } else if (viewText != null) {
        // No picture
        dividerParams.addRule(RelativeLayout.BELOW, viewText.getId());
    } else {
        Timber.e("Tried to add divider to uninitialized ATVWidget");
        return;
    }
    addView(v, dividerParams);
}

From source file:com.google.sample.cast.refplayer.Synchronization.java

/**
 *  Setting the Normal Clip bar(orange)/*from  w  ww. ja v  a  2  s. c  om*/
 */
private void SetNormalClipBar() {
    /**
     *  Setting the clip bar (orange) */
    prev_end_p = (int) mDuration;
    seekBar = new RangeSeekBar(0, (int) mDuration, this);
    seekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>() {
        @Override
        public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer start_p, Integer end_p) {
            // handle changed range values
            Log.i(TAG, "Selected new range values: MIN=" + start_p + ", MAX=" + end_p);

            CurSysTime = System.currentTimeMillis();
            if (end_p > (CurSysTime - SysStartTime)) {
                seekBar.setSelectedMaxValue((int) (CurSysTime - SysStartTime));
                prev_end_p = (int) (CurSysTime - SysStartTime);
                seekVideoView();
                mVideoView.start();
                SystemClock.sleep(100);
                mVideoView.pause();
                mPreview.setVisibility(View.VISIBLE);
                if (condition == 2)
                    mSendClip.setVisibility(View.VISIBLE);
                SetReturnBtn();
            } else if (condition == 2 || condition == 3) {
                // Clip Condition
                mClipDuration.setText("  " + com.google.android.libraries.cast.companionlibrary.utils.Utils
                        .formatMillis(prev_end_p - prev_start_p) + "  ");
                mPreview.setVisibility(View.VISIBLE);
                if (condition == 2) {
                    mSendClip.setVisibility(View.VISIBLE);
                }
                SetReturnBtn();

                if (start_p != prev_start_p) {
                    mCurTime = start_p;
                    seekVideoView();

                    prev_start_p = start_p;
                    mVideoView.start();
                    SystemClock.sleep(100);
                    mVideoView.pause();
                }
                if (end_p != prev_end_p) {
                    mCurTime = end_p;
                    seekVideoView();

                    prev_end_p = end_p;
                    mVideoView.start();
                    SystemClock.sleep(100);
                    mVideoView.pause();
                }
            }

        }
    });
    seekVideoView();
    seekBar.setSelectedMaxValue(mCurTime); //Let the rangeseekbar start at the begin

    // add RangeSeekBar to pre-defined layout
    RelativeLayout layout = (RelativeLayout) findViewById(R.id.synchronization);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, seekBar.getId());
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, seekBar.getId());
    params.addRule(RelativeLayout.BELOW, mVideoView.getId());
    seekBar.setVisibility(View.VISIBLE);
    layout.addView(seekBar, params);
}