Search code examples
androidkotlinandroid-layout

Android - make view overflow visible / render it


<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="0dp"
    android:layout_height="52dp"
    android:layout_marginHorizontal="20dp"
    android:background="@android:color/white"
    android:clipToPadding="false"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent">

    <ImageView
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_marginTop="-12dp"
        android:layout_marginEnd="-12dp"
        android:alpha=".50"
        app:srcCompat="@drawable/ic_close_two"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

The overflow of the ImageView doesn't show but it's cut off beyond the border, how to fix it?


Solution

  • Set android:clipChildren="false" to all ascendants of the ConstraintLayout to prevent having children clipped to the borders of their ViewGroups.

    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipChildren="false"
        android:gravity="center">
    
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="52dp"
            android:layout_height="52dp"
            android:layout_marginHorizontal="20dp"
            android:background="@android:color/holo_blue_light"
            android:clipToPadding="false"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent">
    
            <ImageView
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_marginTop="-12dp"
                android:layout_marginEnd="-12dp"
                android:alpha=".50"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/circle" />
    
        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.appcompat.widget.LinearLayoutCompat>
    

    enter image description here