在开始时定义要在xml中滚动的视图

时间:2019-01-17 10:47:56

标签: android scrollview xml-layout

我的片段开始时加载一个简单的布局:

<ScrollView
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <View
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/firstView" />

        <View
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/secondView" />
    </LinearLayout>
</ScrollView>

片段开始时,我希望我的firstView被隐藏起来,而当用户向下滚动时,它应该与secondView一起移动,以使其可见。

基本上,我希望我的ScrollView从负位置开始。问题是我不知道firstView的高度。

是否可以使用xml属性定义此行为?

致谢,
朗恰克

1 个答案:

答案 0 :(得分:0)

好吧,可以使用CollapsingToolbarLayout完成。

材料设计规范:https://material.io/develop/android/components/collapsing-toolbar-layout/