Example usage for android.widget RelativeLayout ALIGN_PARENT_END

List of usage examples for android.widget RelativeLayout ALIGN_PARENT_END

Introduction

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

Prototype

int ALIGN_PARENT_END

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

Click Source Link

Document

Rule that aligns the child's end edge with its RelativeLayout parent's end edge.

Usage

From source file:com.l4digital.fastscroll.FastScroller.java

public void setLayoutParams(@NonNull ViewGroup viewGroup) {
    if (viewGroup instanceof CoordinatorLayout) {
        CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) getLayoutParams();
        @IdRes//w  w  w.j  a  v a 2s . c  o  m
        int layoutId = mRecyclerView.getId();

        if (layoutId != NO_ID) {
            layoutParams.setAnchorId(layoutId);
            layoutParams.anchorGravity = GravityCompat.END;
        } else {
            layoutParams.gravity = GravityCompat.END;
        }
        setLayoutParams(layoutParams);
    } else if (viewGroup instanceof FrameLayout) {
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) getLayoutParams();

        layoutParams.gravity = GravityCompat.END;
        setLayoutParams(layoutParams);
    } else if (viewGroup instanceof RelativeLayout) {
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
        } else {
            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        }
        setLayoutParams(layoutParams);
    } else {
        throw new IllegalArgumentException(
                "Parent ViewGroup must be a CoordinatorLayout, FrameLayout, or RelativeLayout");
    }
}

From source file:com.adithyaupadhya.uimodule.roundcornerprogressbar.BaseRoundCornerProgressBar.java

private void setupReverse(LinearLayout layoutProgress) {
    RelativeLayout.LayoutParams progressParams = (RelativeLayout.LayoutParams) layoutProgress.getLayoutParams();
    removeLayoutParamsRule(progressParams);
    if (isReverse) {
        progressParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        // For support with RTL on API 17 or more
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
            progressParams.addRule(RelativeLayout.ALIGN_PARENT_END);
    } else {/*from w  w  w  .j a va2 s . c  o  m*/
        progressParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        // For support with RTL on API 17 or more
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
            progressParams.addRule(RelativeLayout.ALIGN_PARENT_START);
    }
    layoutProgress.setLayoutParams(progressParams);
}

From source file:com.markupartist.sthlmtraveling.ui.view.TripView.java

public void updateViews() {
    this.setOrientation(VERTICAL);

    float scale = getResources().getDisplayMetrics().density;

    this.setPadding(getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding),
            getResources().getDimensionPixelSize(R.dimen.list_vertical_padding),
            getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding),
            getResources().getDimensionPixelSize(R.dimen.list_vertical_padding));

    LinearLayout timeStartEndLayout = new LinearLayout(getContext());
    TextView timeStartEndText = new TextView(getContext());
    timeStartEndText.setText(DateTimeUtil.routeToTimeDisplay(getContext(), trip));
    timeStartEndText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1));
    timeStartEndText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);

    ViewCompat.setPaddingRelative(timeStartEndText, 0, 0, 0, (int) (2 * scale));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (RtlUtils.isRtl(Locale.getDefault())) {
            timeStartEndText.setTextDirection(View.TEXT_DIRECTION_RTL);
        }//www  .ja v a 2s  . co  m
    }

    // Check if we have Realtime for start and or end.
    boolean hasRealtime = false;
    Pair<Date, RealTimeState> transitTime = trip.departsAt(true);
    if (transitTime.second != RealTimeState.NOT_SET) {
        hasRealtime = true;
    } else {
        transitTime = trip.arrivesAt(true);
        if (transitTime.second != RealTimeState.NOT_SET) {
            hasRealtime = true;
        }
    }
    //        if (hasRealtime) {
    //            ImageView liveDrawable = new ImageView(getContext());
    //            liveDrawable.setImageResource(R.drawable.ic_live);
    //            ViewCompat.setPaddingRelative(liveDrawable, 0, (int) (2 * scale), (int) (4 * scale), 0);
    //            timeStartEndLayout.addView(liveDrawable);
    //
    //            AlphaAnimation animation1 = new AlphaAnimation(0.4f, 1.0f);
    //            animation1.setDuration(600);
    //            animation1.setRepeatMode(Animation.REVERSE);
    //            animation1.setRepeatCount(Animation.INFINITE);
    //
    //            liveDrawable.startAnimation(animation1);
    //        }

    timeStartEndLayout.addView(timeStartEndText);

    LinearLayout startAndEndPointLayout = new LinearLayout(getContext());
    TextView startAndEndPoint = new TextView(getContext());
    BidiFormatter bidiFormatter = BidiFormatter.getInstance(RtlUtils.isRtl(Locale.getDefault()));
    startAndEndPoint.setText(String.format("%s  %s", bidiFormatter.unicodeWrap(trip.fromStop().getName()),
            bidiFormatter.unicodeWrap(trip.toStop().getName())));

    startAndEndPoint.setTextColor(getResources().getColor(R.color.body_text_1)); // Dark gray
    startAndEndPoint.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (RtlUtils.isRtl(Locale.getDefault())) {
            startAndEndPoint.setTextDirection(View.TEXT_DIRECTION_RTL);
        }
    }
    ViewCompat.setPaddingRelative(startAndEndPoint, 0, (int) (4 * scale), 0, (int) (4 * scale));
    startAndEndPointLayout.addView(startAndEndPoint);

    RelativeLayout timeLayout = new RelativeLayout(getContext());

    LinearLayout routeChanges = new LinearLayout(getContext());
    routeChanges.setGravity(Gravity.CENTER_VERTICAL);

    LinearLayout.LayoutParams changesLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    changesLayoutParams.gravity = Gravity.CENTER_VERTICAL;

    if (trip.hasAlertsOrNotes()) {
        ImageView warning = new ImageView(getContext());
        warning.setImageResource(R.drawable.ic_trip_deviation);
        ViewCompat.setPaddingRelative(warning, 0, (int) (2 * scale), (int) (4 * scale), 0);
        routeChanges.addView(warning);
    }

    int currentTransportCount = 1;
    int transportCount = trip.getLegs().size();
    for (Leg leg : trip.getLegs()) {
        if (!leg.isTransit() && transportCount > 3) {
            if (leg.getDistance() < 150) {
                continue;
            }
        }
        if (currentTransportCount > 1 && transportCount >= currentTransportCount) {
            ImageView separator = new ImageView(getContext());
            separator.setImageResource(R.drawable.transport_separator);
            ViewCompat.setPaddingRelative(separator, 0, 0, (int) (2 * scale), 0);
            separator.setLayoutParams(changesLayoutParams);
            routeChanges.addView(separator);
            if (RtlUtils.isRtl(Locale.getDefault())) {
                ViewCompat.setScaleX(separator, -1f);
            }
        }

        ImageView changeImageView = new ImageView(getContext());
        Drawable transportDrawable = LegUtil.getTransportDrawable(getContext(), leg);
        changeImageView.setImageDrawable(transportDrawable);
        if (RtlUtils.isRtl(Locale.getDefault())) {
            ViewCompat.setScaleX(changeImageView, -1f);
        }
        ViewCompat.setPaddingRelative(changeImageView, 0, 0, 0, 0);
        changeImageView.setLayoutParams(changesLayoutParams);
        routeChanges.addView(changeImageView);

        if (currentTransportCount <= 3) {
            String lineName = leg.getRouteShortName();
            if (!TextUtils.isEmpty(lineName)) {
                TextView lineNumberView = new TextView(getContext());
                lineNumberView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
                RoundedBackgroundSpan roundedBackgroundSpan = new RoundedBackgroundSpan(
                        LegUtil.getColor(getContext(), leg), Color.WHITE,
                        ViewHelper.dipsToPix(getContext().getResources(), 4));
                SpannableStringBuilder sb = new SpannableStringBuilder();
                sb.append(lineName);
                sb.append(' ');
                sb.setSpan(roundedBackgroundSpan, 0, lineName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                lineNumberView.setText(sb);

                ViewCompat.setPaddingRelative(lineNumberView, (int) (5 * scale), (int) (1 * scale),
                        (int) (2 * scale), 0);
                lineNumberView.setLayoutParams(changesLayoutParams);
                routeChanges.addView(lineNumberView);
            }
        }

        currentTransportCount++;
    }

    TextView durationText = new TextView(getContext());
    durationText.setText(DateTimeUtil.formatDetailedDuration(getResources(), trip.getDuration() * 1000));
    durationText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1));
    durationText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    durationText.setTypeface(Typeface.DEFAULT_BOLD);

    timeLayout.addView(routeChanges);
    timeLayout.addView(durationText);

    RelativeLayout.LayoutParams durationTextParams = (RelativeLayout.LayoutParams) durationText
            .getLayoutParams();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_END);
    } else {
        durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    }
    durationText.setLayoutParams(durationTextParams);

    View divider = new View(getContext());
    ViewGroup.LayoutParams dividerParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
    divider.setLayoutParams(dividerParams);

    this.addView(timeLayout);

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) routeChanges.getLayoutParams();
    params.height = LayoutParams.MATCH_PARENT;
    params.addRule(RelativeLayout.CENTER_VERTICAL);
    routeChanges.setLayoutParams(params);

    this.addView(startAndEndPointLayout);
    this.addView(timeStartEndLayout);

    if (mShowDivider) {
        this.addView(divider);
    }
}

From source file:com.adithyaupadhya.uimodule.roundcornerprogressbar.BaseRoundCornerProgressBar.java

private void removeLayoutParamsRule(RelativeLayout.LayoutParams layoutParams) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_END);
        layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_LEFT);
        layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_START);
    } else {/* w  ww. ja  v  a 2 s.  c o  m*/
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
    }
}

From source file:com.jaus.albertogiunta.justintrain_oraritreni.journeyFavourites.FavouriteJourneysActivity.java

@Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
    if (result.isFailure()) {

    } else {//from w w w  .java2s.  co m
        if (CustomIABHelper.isOrderOk(result, inv)) {
            if (ignoreBeingProAndShowAds) {
                apply(btnIAP, VISIBLE);
                loadAds();
            } else {
                ProPreferences.enablePro(getViewContext());
                if (isFirstStart)
                    ProPreferences.enableAllPro(getViewContext());
                if (isFirstStartAfterUpdate && previousVersionCode < 47)
                    ProPreferences.enableCompactNotification(getViewContext());
                apply(btnIAP, GONE);
                Ads.removeAds(rlBannerPlaceholder, adView2);
                hideIAPButton();
                shouldDisplayDiscountMessage = false;
                invalidateOptionsMenu();
            }
        } else {
            ProPreferences.disableAllPro(getViewContext());
            apply(btnIAP, VISIBLE);
            RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) btnSearch.getLayoutParams();
            lp.addRule(RelativeLayout.ALIGN_PARENT_END);
            btnSearch.setLayoutParams(lp);
            shouldDisplayDiscountMessage = true;
            loadAds();

        }
    }
    setVisibilityOfProBedge();
}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Set the icon on the alert//w w  w.  j  a  v a 2  s.c  o  m
 *
 * @param context       application-specific resources
 * @param configuration describes all device configuration information
 * @param mainView      ViewGroup resources
 * @param textView      alert message to be viewed message to be displayedView
 */
@SuppressLint("NewApi")
private static void setIcon(Activity context, Configuration configuration, ViewGroup mainView,
        TextView textView) {

    ImageView imageView = (ImageView) mainView.findViewById(R.id.alert_view_icon);

    // Reset the current icon
    if (imageView != null) {
        mainView.removeView(imageView);
    }

    // On the textview as well
    textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    textView.setCompoundDrawablePadding(0);

    if (configuration.getIconResId() != -1) {

        imageView = new ImageView(context);
        imageView.setId(R.id.alert_view_icon);

        imageView.setImageResource(configuration.getIconResId());
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        imageView.setLayoutParams(layoutParams);

        switch (configuration.getIconPosition()) {
        case LEFT_TEXT:
            textView.setCompoundDrawablesWithIntrinsicBounds(configuration.getIconResId(), 0, 0, 0);
            textView.setCompoundDrawablePadding(10);
            break;

        case RIGHT_TEXT:
            textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, configuration.getIconResId(), 0);
            textView.setCompoundDrawablePadding(10);
            break;

        case LEFT:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
            }

            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            layoutParams.setMargins(25, 0, 0, 0);
            mainView.addView(imageView);

            // We redefine the layout params otherwise the image is not well aligned
            textView.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            break;
        case RIGHT:
        default:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
            }

            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            layoutParams.setMargins(0, 0, 25, 0);
            mainView.addView(imageView);

            // We redefine the layout params otherwise the image is not well aligned
            textView.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            break;
        }
    }
}

From source file:de.sourcestream.movieDB.controller.CastDetails.java

/**
 * Updates the icons position when called.
 *///from   w  w  w .  ja v a  2 s  .  c o m
public void updateDownPos() {
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(moreIcon.getWidth(), moreIcon.getHeight());
    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(homeIcon.getWidth(),
            homeIcon.getHeight());
    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(galleryIcon.getWidth(),
            galleryIcon.getHeight());
    lp.addRule(RelativeLayout.ALIGN_PARENT_END);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_END);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_END);

    lp.setMargins(0,
            (int) (scale * (496 + iconMarginConstant - iconMarginLandscape + iconConstantSpecialCase) + 0.5f),
            (int) (scale * 15 + 0.5f), 0);
    moreIcon.setLayoutParams(lp);
    lp1.setMargins(0,
            (int) (scale * (439 + iconMarginConstant - iconMarginLandscape + iconConstantSpecialCase) + 0.5f),
            (int) (scale * 23 + 0.5f), 0);
    homeIcon.setLayoutParams(lp1);
    lp2.setMargins(0,
            (int) (scale * (383.3 + iconMarginConstant - iconMarginLandscape + iconConstantSpecialCase) + 0.5f),
            (int) (scale * 23 + 0.5f), 0);
    galleryIcon.setLayoutParams(lp2);
}

From source file:de.sourcestream.movieDB.controller.CastDetails.java

/**
 * Updates the icons position when called.
 *///from  www  .  j a va 2s  .  c o m
public void updateUpPos() {
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(moreIcon.getWidth(), moreIcon.getHeight());
    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(homeIcon.getWidth(),
            homeIcon.getHeight());
    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(galleryIcon.getWidth(),
            galleryIcon.getHeight());
    lp.addRule(RelativeLayout.ALIGN_PARENT_END);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_END);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_END);

    lp.setMargins(0, (int) (scale * (346 + iconMarginConstant) + 0.5f - castDetailsInfoScrollY),
            (int) (scale * 15 + 0.5f), 0);
    moreIcon.setLayoutParams(lp);
}

From source file:de.sourcestream.movieDB.controller.MovieDetails.java

/**
 * Updates the icons position when called.
 *//*from ww  w  .jav  a 2s .  com*/
public void updateDownPos() {
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(moreIcon.getWidth(), moreIcon.getHeight());
    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(homeIcon.getWidth(),
            homeIcon.getHeight());
    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(trailerIcon.getWidth(),
            trailerIcon.getHeight());
    RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(galleryIcon.getWidth(),
            galleryIcon.getHeight());
    lp.addRule(RelativeLayout.ALIGN_PARENT_END);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_END);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_END);
    lp3.addRule(RelativeLayout.ALIGN_PARENT_END);

    lp.setMargins(0,
            (int) (scale * (496 + iconMarginConstant - iconMarginLandscape + iconConstantSpecialCase) + 0.5f),
            (int) (scale * 15 + 0.5f), 0);
    moreIcon.setLayoutParams(lp);
    lp1.setMargins(0,
            (int) (scale * (439 + iconMarginConstant - iconMarginLandscape + iconConstantSpecialCase) + 0.5f),
            (int) (scale * 23 + 0.5f), 0);
    homeIcon.setLayoutParams(lp1);
    lp2.setMargins(0,
            (int) (scale * (383.3 + iconMarginConstant - iconMarginLandscape + iconConstantSpecialCase) + 0.5f),
            (int) (scale * 23 + 0.5f), 0);
    trailerIcon.setLayoutParams(lp2);
    lp3.setMargins(0,
            (int) (scale * (328.3 + iconMarginConstant - iconMarginLandscape + iconConstantSpecialCase) + 0.5f),
            (int) (scale * 23 + 0.5f), 0);
    galleryIcon.setLayoutParams(lp3);
}

From source file:de.sourcestream.movieDB.controller.TVDetails.java

/**
 * Updates the icons position when called.
 *//*www .  j  av  a2s .  c  om*/
public void updateUpPos() {
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(moreIcon.getWidth(), moreIcon.getHeight());
    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(homeIcon.getWidth(),
            homeIcon.getHeight());
    RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(galleryIcon.getWidth(),
            galleryIcon.getHeight());
    lp.addRule(RelativeLayout.ALIGN_PARENT_END);
    lp1.addRule(RelativeLayout.ALIGN_PARENT_END);
    lp2.addRule(RelativeLayout.ALIGN_PARENT_END);

    lp.setMargins(0, (int) (scale * (346 + iconMarginConstant) + 0.5f - tvDetailsInfoScrollY),
            (int) (scale * 15 + 0.5f), 0);
    moreIcon.setLayoutParams(lp);
}