【发布时间】:2017-03-30 09:46:42
【问题描述】:
我想要类似于下面问的问题,而不是“视图 1”,它将是一个滚动视图: android: Create layout which collapse on scrolling
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:background="#456342"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"
android:clickable="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:theme="@style/AppTheme.AppBarOverlay"
app:contentScrim="?attr/colorPrimary">
<android.support.v7.widget.Toolbar
android:id="@+id/activity_subcard_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_collapseMode="pin"/>
<include layout="@layout/activity_sub_card_content1"
android:layout_height="200dp"
android:layout_width="match_parent"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/activity_sub_card_content2" />
</android.support.design.widget.CoordinatorLayout>
下面给出的 xml 代码是我的布局“activity_sub_card_content1”,我已包含在我的 CollapsingToolbarLayout 中。我想要类似的东西:
How to place a layout below toolbar in collapsing toolbar layout?
但它的相对布局不太长。我的会很长,所以我想把我的布局放在滚动视图中。
我尝试的代码显示了我的滚动视图,但它不滚动它,而是折叠工具栏。
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/trial"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:clickable="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_margin="20dp"
android:layout_width="match_parent"
android:layout_height="200dp">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_margin="20dp"
android:layout_width="match_parent"
android:layout_height="200dp">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_margin="20dp"
android:layout_width="match_parent"
android:layout_height="200dp">
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_margin="20dp"
android:layout_width="match_parent"
android:layout_height="200dp">
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
【问题讨论】:
标签: android android-layout scrollview android-coordinatorlayout android-collapsingtoolbarlayout