How to Avoid Parent Scrollview to Clip Internal Scrollview

How to prevent child Views overlapping their parent ScrollView?

Try to add clip shape (because it is not ScrollView but your custom added background has rounded corners), like

ScrollView(.vertical, showsIndicators: true) {

// .. content here

}.background(
RoundedRectangle(cornerRadius: 15)
.foregroundColor(Color("LightBlack70%"))
).clipShape(
RoundedRectangle(cornerRadius: 15)
).frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)

How to prevent *locked* parent scroll-view from scrolling when nested child scroll-view scrolls to end of its view?

You are nesting multiple ScrollViews inside a FlatList, which is a convenience wrapper around ScrollView (compare with the documentation) , but you are setting nestedScrolEnabled to true in the child ScrollViews. You need to set it on the parent ScrollView (the FlatList).

The following code completely disables scrolling for the parent FlatList while allowing scrolling in all nested ScrollViews.

const _renderItem = ({item, index}) => {
return (
<View style={{height: 300, borderColor: 'blue', borderWidth: 1, marginBottom: 20}}>
<Text> Non scroll View area </Text>
<ScrollView contentContainerStyle={{height: 500, borderColor: 'red', borderWidth: 3}}></ScrollView>
</View>
)
}
return (
<View style={styles.container}>
<FlatList data={data} renderItem={_renderItem} scrollEnabled={false} nestedScrollEnabled={true}/>
</View>
);
}

Here is a working snack of your code with the changes mentioned above which I have successfully tested on Android (Samsung Galaxy S9) and iOS (iPhone 12).

Bottom of ScrollView clipped when using ConstraintLayout

The way I would have done it is:

<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_test"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#212121"
android:text="Constraint Layout"
android:textSize="45sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/header">

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="BUTTON"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />

</android.support.constraint.ConstraintLayout>

</ScrollView>

</android.support.constraint.ConstraintLayout>

Which gives:

Sample Image

A few things to keep in mind:

  • you don't need a linearlayout for the header, you can just use the textview directly.
  • don't use match_parent, it might seem to work, but is undefined. Use 0dp instead with the correct constraints to stretch the view as you want.
  • clearly, don't use a 800dp margin. It might look ok on your particular screen, but won't give you what you want on different devices.
  • scrollview by default will wrap its content -- the fillViewport attribute is here to make it takes the indicated space
  • you can use nested ConstraintLayout when it makes sense. In the future, we might also take advantage of it to do some performance improvements

How to make ScrollView clip only vertically?

I can only imagine one reason, why you don't set the ScrollView's width to a higher value (the contentItem's width).

To be able to do so, while not constraining the ScrollView in it's width, you can use a simple trick:

Item {
id: limitedWidthItemToAnchorTo
width: 200 // the width the ScrollView was supposed to have
height: 400

ScrollView {
width: contentItem.width + __verticalScrollBar.width// Don't limit the width.
height: 400 // Limit only the height.
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff // You don't need them.
contentItem: Rectangle {
width: 700 // This will set the ScrollViews width.
height: 600 // The height will be clipped by the ScrollView.
// You can scroll though.

gradient: Gradient {
GradientStop { position: 0; color: 'red' }
GradientStop { position: 1; color: 'blue' }
}
border.width: 10
}
}
}

You'll wrap it in the Item, anchor to this, and you'll be good.
Alternatively you could use masks, but this would be... more complicated.

Per se it is not possible to clip only horizontal or vertical, as the clipping is done using the Item's bounding box.

ScrollView Inside ScrollView

Is this close enough?

You should never use a
HorizontalScrollView with a ListView,
since ListView takes care of its own
scrolling. Most importantly, doing
this defeats all of the important
optimizations in ListView for dealing
with large lists, since it effectively
forces the ListView to display its
entire list of items to fill up the
infinite container supplied by
HorizontalScrollView.

http://developer.android.com/reference/android/widget/HorizontalScrollView.html

UPDATE:

Since you may be forced to use a two dimensional scrollview, you may consider using this:
Internet archive of blog.gorges.us/2010/06/android-two-dimensional-scrollview/

I haven't used this but it may be a reasonable approach.

Avoiding multiple Scroll when textview is used inside Scrollview ios

I believe you're asking how to have just a single scrollable area, basically all the views of the ViewController.

Set your textView's scrollEnabled option to false. It should cause the intrinsic height of the textView to become the height to display all the text, so you'll no longer have a scroll view inside a scrollview. Make sure you don't specify the height of the textView, otherwise it'll cut off the text.

Okay. I've created a demo project with what I think you're looking for.

Here's some explanation.

The scrollView's constraints to it's parent and sibling views define it's frame size.

The constraints from the scrollView's subviews to the scrollView define the contentSize.

With that in mind. Set the scrollView to be centered in it's superview and have the same width and height. (Now the scrollView's frame is defined).

To define the scrollview's contentSize we setup top, leading, trailing, bottom constraints using the scrollView's children. (Now the scrollView's contentSize is created)

If you don't have to have scrolling in the horizontal direction you need to make sure the children's width is less than of equals to the scrollView's superview.

I hope this information helps.



Related Topics



Leave a reply



Submit