Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – How to make a view in ConstraintLayout to be bigger than its parent?

Posted on November 14, 2022

Solution 1 :

This can be accomplished by establishing two 200dp x 200dp Space widgets outside the bounds of the ConstraintLayout. (This works, but I am not necessarily recommending its use. My only objection would be that it is kinda hackish.)

Create two space widgets that are 200dp x 200dp. Constrain the lower right corner of one to the upper left corner of the ConstraintLayout and the upper left corner of the other widget to the bottom right corner of the layout. Now constrain your view to the outer boundaries of these Space widget. You view will not stretch 200dp outside the boundary of the ConstraintLayout on all sides.

<androidx.constraintlayout.widget.ConstraintLayout 
    android_layout_width="match_parent"
    android_layout_height="match_parent"
    tools_context=".MainActivity">

    <Space
        android_id="@+id/topLeft"
        android_layout_width="200dp"
        android_layout_height="200dp"
        app_layout_constraintBottom_toTopOf="parent"
        app_layout_constraintEnd_toStartOf="parent"/>

    <Space
        android_id="@+id/bottomRight"
        android_layout_width="200dp"
        android_layout_height="200dp"
        app_layout_constraintTop_toBottomOf="parent"
        app_layout_constraintStart_toEndOf="parent"/>

    <View
        android_id="@+id/backgroundView"
        android_layout_width="0dp"
        android_layout_height="0dp"
        android_background="@drawable/main_background"
        app_layout_constraintEnd_toEndOf="@id/bottomRight"
        app_layout_constraintBottom_toBottomOf="@id/bottomRight"
        app_layout_constraintStart_toStartOf="@id/topLeft"
        app_layout_constraintTop_toTopOf="@id/topLeft" />
</androidx.constraintlayout.widget.ConstraintLayout>

In the image below, you can see the faint outline of the Space widgets.

enter image description here

Problem :

I have an Activity with ConstraintLayout, and a view in it:

<androidx.constraintlayout.widget.ConstraintLayout xmlns_android="http://schemas.android.com/apk/res/android"
    xmlns_app="http://schemas.android.com/apk/res-auto"
    xmlns_tools="http://schemas.android.com/tools"
    android_layout_width="match_parent"
    android_layout_height="match_parent"
    tools_context=".presentation.MainActivity">

    <View
        android_id="@+id/backgroundView"
        android_layout_width="match_parent"
        android_layout_height="match_parent"
        android_background="@drawable/main_background" />

I want this view to be bigger than its parent for, for example, 200dp by each side.

On iOS I can just constraint it by (-Npt, -Npt, Npt, Npt) (left, top, right, bottom) to achieve this (on this screen target view is background view with pattern image):

enter image description here

But how to correctly do it on Android with ConstraintLayout

Comments

Comment posted by CommonsWare

That’s not usually done in Android. The closest thing we have ever done for that involved negative margins, and AFAIK those are not supported with

READ  [ANSWERED] Problema em rodar app Flutter no emulador android no VS code
Powered by Inline Related Posts

Comment posted by artem

@CommonsWare yep, negative margins do no work.

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress