Example usage for android.view View setLayoutParams

List of usage examples for android.view View setLayoutParams

Introduction

In this page you can find the example usage for android.view View setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.hippo.nimingban.widget.PostLayout.java

public void onRemoveTypeSend() {
    // Reset post view bottom margin
    View postView = getChildAt(0);
    if (postView != null) {
        LayoutParams lp = (LayoutParams) postView.getLayoutParams();
        lp.bottomMargin = 0;/*  www  . j  av a  2  s  . co m*/
        postView.setLayoutParams(lp);
    }
}

From source file:com.rachelgrau.rachel.health4theworldstroke.Activities.InfoActivity.java

public void addLineBreak() {
    LinearLayout ll = (LinearLayout) findViewById(R.id.text_linear_layout);
    View line = new View(this);
    line.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 3));
    line.setBackgroundColor(ContextCompat.getColor(this, R.color.darkGray));
    ll.addView(line);//w  w w. ja v a2  s .co m
}

From source file:HeaderGridView.java

/** added by Ahmed Basyouni
* this method take supported fragment and fragment activity to add that
* fragment as a banner to listView it create a layout at runtime then when
* view is added to list we replace it with fragment otherwise it will crash
* since view is not on screen to be replaced
* 
* @param fragment//from ww w .j  ava2  s.  c  o  m
* @param activity
*/
public void addBannerFragment(final Fragment fragment, final FragmentActivity activity) {

    RelativeLayout layout = new RelativeLayout(activity);

    AbsListView.LayoutParams param = new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);

    layout.setLayoutParams(param);

    // please don't ever remove that view otherwise application will crash and I mean it :D
    View view = new View(activity);

    view.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 300));

    view.setVisibility(View.INVISIBLE);

    layout.addView(view);

    layout.setId(CONTAINER_ID);

    addHeaderView(layout);

    this.addOnLayoutChangeListener(new OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {

            HeaderGridView.this.removeOnLayoutChangeListener(this);

            FragmentManager manager = activity.getSupportFragmentManager();
            FragmentTransaction transaction = manager.beginTransaction();

            transaction.replace(CONTAINER_ID, fragment).commit();
        }
    });

}

From source file:androidx.mediarouter.app.MediaRouteControllerDialog.java

static void setLayoutHeight(View view, int height) {
    ViewGroup.LayoutParams lp = view.getLayoutParams();
    lp.height = height;/*  w  w w.  ja va 2 s . co  m*/
    view.setLayoutParams(lp);
}

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);
        }/*  w w  w.  j a va  2s .c  om*/
    }

    // 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.laer.easycast.ImagePane.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View root = new View(getActivity());
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    root.setBackgroundColor(Color.WHITE);
    root = inflater.inflate(R.layout.imagepane, container, false);
    setHasOptionsMenu(true);/*from ww w .j  ava  2  s  .c  o m*/
    myViewGroup = container;

    cursor = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,

            projection, // Which columns to return

            null, // Return all rows

            null,

            MediaStore.Images.Media.DEFAULT_SORT_ORDER);

    GridView gridView = (GridView) root.findViewById(R.id.gridView1);

    gridView.setAdapter(new ImageAdapter(getActivity()));

    gridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

            columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToPosition(position);

            // Get image filename
            String imagePath = cursor.getString(columnIndex);
            Bitmap image = BitmapFactory.decodeFile(imagePath);

            Log.i("ImagePath=", imagePath);
            Log.d(TAG, "Image decoded");
            photoRaw(image, NONE);

            // Use this path to do further processing, i.e. full screen
            // display
        }
    });

    return root;
}

From source file:com.emilsjolander.components.stickylistheaders.StickyListHeadersCursorAdapter.java

private View attachDividerToListItem(View listItem) {
    WrapperView wrapper = null;/*from  w  w w.  j a va2 s .c o  m*/
    if (wrapperCache.size() > 0) {
        wrapper = wrapperCache.remove(0);
    }
    if (wrapper == null) {
        wrapper = new WrapperView(context);
    }
    View divider = null;
    if (dividerCache.size() > 0) {
        divider = dividerCache.remove(0);
    }
    if (divider == null) {
        divider = new View(context);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(MATCH_PARENT, dividerHeight);
        divider.setLayoutParams(params);
    }
    divider.setBackgroundDrawable(this.divider);
    return wrapper.wrapViews(listItem, divider, null);
}

From source file:com.mk4droid.IMC_Activities.FActivity_TabHost.java

private LinearLayout make_Active_Tab(String text, Drawable dr) {

    LinearLayout ll = new LinearLayout(this);
    ll.setPadding(0, 0, 2, 1);// w  ww .java 2  s  .c  o m
    ll.setBackgroundColor(Color.GRAY);

    ll.setTag("ll");
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.setLayoutParams(
            new LinearLayout.LayoutParams(0, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, 1));

    //------ Text 
    TextView tv = new TextView(this);
    tv.setBackgroundColor(Color.TRANSPARENT);
    tv.setTag("tv");
    ll.addView(tv);

    // ------ hbar
    View hbar = new View(this);
    hbar.setTag("hbar");
    hbar.setLayoutParams(
            new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.FILL_PARENT, 10));

    ll.addView(hbar);

    ////////////////////////////////////////
    return ActivateColorize(ll, text, dr);
}

From source file:com.mk4droid.IMC_Activities.FActivity_TabHost.java

private LinearLayout make_Inactive_Tab(String text, Drawable dr) {

    LinearLayout ll = new LinearLayout(this);

    ll.setPadding(0, 0, 2, 1);//from w  w w  . j  a  v a2s .  c o m

    ll.setBackgroundColor(Color.GRAY);

    ll.setTag("ll");
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.setLayoutParams(
            new LinearLayout.LayoutParams(0, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, 1));

    //------ Text 
    TextView tv = new TextView(this);
    tv.setBackgroundColor(Color.TRANSPARENT);
    tv.setTag("tv");
    ll.addView(tv);

    // ------ hbar
    View hbar = new View(this);
    hbar.setTag("hbar");
    hbar.setLayoutParams(
            new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.FILL_PARENT, 10));

    ll.addView(hbar);

    /////////////////////////////////////
    return InActivateColorize(ll, text, dr);
}

From source file:com.saulmm.cui.OrderDialogFragment.java

private void startCloneAnimation(View clonedView, View targetView) {
    clonedView.post(() -> {//from w w w.  j  av  a2 s . co m
        TransitionManager.beginDelayedTransition((ViewGroup) binding.getRoot(), selectedViewTransition);

        // Fires the transition
        clonedView.setLayoutParams(SelectedParamsFactory.endParams(clonedView, targetView));
    });
}