Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.
This repository was archived by the owner on May 14, 2025. It is now read-only.

Anchor contents to bottom #59

@shaurya947

Description

@shaurya947

I'm using ContourLayout to build a view that will be placed inside a ScrollView (with fillViewport="true"). When scrolling is not required, I'd like for the contents to be anchored to the bottom of the ScrollView.

Here is how I'm going about it (for simplicity, let's just say there are 2 children views):

class MyContourView(
    context: Context,
    private val view1: View,
    private val view2: View,
    private val interItemMarginPx: Int,
    private val lrMarginPx: Int
) : ContourLayout(context) {
    init {
        contourHeightOf { availableHeight ->
            maxOf(availableHeight, view2.bottom() + interItemMarginPx
        }
    }

    override fun onInitializeLayout() {
        view2.applyLayout(
            leftTo { parent.left() + lrMarginPx }.rightTo { parent.right() - lrMarginPx },
            bottomTo { parent.bottom() - interItemMarginPx }
        )

        view1.applyLayout(
            leftTo { parent.left() + lrMarginPx }.rightTo { parent.right() - lrMarginPx },
            bottomTo { view2.top() - interItemMarginPx }
        )
    }
}

But I get a CircularReferenceDetected error (at the line where I call view2.bottom() in contourHeightOf {}). I can see why that's the case: view2 references parent.bottom() and the parent references view2.bottom() in determining its height.

Everything works if I remove the contourHeightOf {} block -- in which case it's always going to be availableHeight. But this breaks the scrolling if the height of the contents is greater than availableHeight.

How do I go about this use case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions