ネストされたスクロールビューは、下にスクロールするとスムーズにスクロールしますが、上にスクロールすると遅くなります。上にスクロールすると折りたたまれたツールバー(画像ビューとフレームレイアウト)は、コンテンツをレンダリングしません(空白のままです)。折りたたみツールバーですべてのフラグを試しました。
<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:id="@+id/coordinatorLayout"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:fitsSystemWindows="true">
<Android.support.design.widget.AppBarLayout
Android:id="@+id/appbar"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:fitsSystemWindows="true"
Android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<Android.support.design.widget.CollapsingToolbarLayout
Android:id="@+id/collapsing_toolbar"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
Android:id="@+id/backdrop"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:minHeight="100dp"
Android:fitsSystemWindows="true"
Android:scaleType="centerCrop"
Android:src="@drawable/pic"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.5"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"/>
<include
Android:id="@+id/framelayout"
layout="@layout/header_layout"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
Android:minHeight="100dp"/>
</Android.support.design.widget.CollapsingToolbarLayout>
</Android.support.design.widget.AppBarLayout>
<!-- Your Scrollable View -->
<Android.support.v4.widget.NestedScrollView
Android:id="@+id/nested"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:orientation="vertical"
Android:paddingTop="24dp">
</LinearLayout>
</Android.support.v4.widget.NestedScrollView>
<Android.support.v7.widget.Toolbar
Android:id="@+id/toolbar"
Android:layout_width="match_parent"
Android:layout_height="?attr/actionBarSize"
Android:background="#da1b75"
Android:orientation="horizontal"
Android:textColor="#ffffff"
Android:theme="@style/ThemeOverlay.AppCompat.Light"
app:layout_anchor="@id/appbar"
app:layout_collapseMode="pin"
app:title="">
</Android.support.v7.widget.Toolbar>
ネストされたscrollviewの直接の子をクリック可能にします(子要素が1つだけではない場合は、レイアウトを追加してすべてのUI要素をその中に配置し、レイアウトをクリック可能にします)
Android:clickable = "true"
同様の問題に直面していましたが、これでうまくいきました!
これが私が取り組んでいるコードです-
<?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"
tools:context="test.testrecycler.MaterialActivity"
>
<Android.support.design.widget.AppBarLayout
Android:layout_width="match_parent"
Android:layout_height="300dp"
Android:theme="@style/AppTheme.AppBarOverlay"
Android:fitsSystemWindows="true"
>
<Android.support.design.widget.CollapsingToolbarLayout
Android:id="@+id/collapsing_toolbar"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleTextAppearance="@style/expandedappbar"
app:collapsedTitleTextAppearance="@style/collapsedappbar"
app:statusBarScrim="@color/colorPrimaryDark"
>
<ImageView
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:src="@drawable/sample"
Android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<Android.support.v7.widget.Toolbar
Android:id="@+id/toolbar"
Android:layout_width="match_parent"
Android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</Android.support.design.widget.CollapsingToolbarLayout>
</Android.support.design.widget.AppBarLayout>
<include layout="@layout/content_material" />
</Android.support.design.widget.CoordinatorLayout>
そして、これがNestedScrollViewを持つファイルcontent_material.xmlです。クリック可能にされた1つの子要素(TextView)があります。
<?xml version="1.0" encoding="utf-8"?>
<Android.support.v4.widget.NestedScrollView 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:id="@+id/content_material"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:paddingBottom="@dimen/activity_vertical_margin"
Android:paddingLeft="@dimen/activity_horizontal_margin"
Android:paddingRight="@dimen/activity_horizontal_margin"
Android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="test.testrecycler.MaterialActivity"
tools:showIn="@layout/activity_material">
<TextView
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:clickable="true"
Android:text="This is an association football club formed in 1983, based in the town of Dover, Kent, England. In the 1989–90 season Dover
Athletic won the Southern League championship, but failed to gain promotion to the Football Conference as the club's ground did not meet
the required standard. Three seasons later the team won the title again and this time gained promotion to the Conference, where they spent
nine seasons before being relegated. The club was transferred to the Isthmian League Premier Division in 2004, but another poor season led
the club to a further relegation. After three seasons in the Isthmian League Division One South, the club won the championship and promotion
back to the Premier Division, and the following season won another championship and promotion to Conference South. In the 2013–14 season,
Dover defeated Ebbsfleet United to return to the Conference Premier after a twelve-year absence. Nicknamed the Whites for their white shirts,
they have played at the Crabble Athletic Ground since the club's formation. Their best performance in the FA Cup was reaching the third
round proper in both the 2010–11 and 2014–15 seasons. (Full article...)
Recently featured: Kalki Koechlin Rogue River (Oregon) Operation Ironside
Archive By email More featured articles...
his time gained promotion to the Conference, where they spent
nine seasons before being relegated. The club was transferred to the Isthmian League Premier Division in 2004, but another poor season led
the club to a further relegation. After three seasons in the Isthmian League Division One South, the club won the championship and promotion
back to the Premier Division, and the following season won another championship and promotion to Conference South. In the 2013–14 season,
Dover defeated Ebbsfleet United to return to the Conference Premier after a twelve-year absence. Nicknamed the Whites for their white shirts,
they have played at the Crabble Athletic Ground since the club's formation. Their best performance in the FA Cup was reaching the third
round proper in both the 2010–11 and 2014–15 seasons. (Full article...)" />
</Android.support.v4.widget.NestedScrollView>
更新:Android STUDIOで画像を右クリックして画像をwebpに変換するだけで画像サイズを縮小できます。これにより、画像サイズが大幅に縮小されます
とてもシンプルです。私は多くの苦労をして、ようやくImageViewのsrcに配置した高解像度画像の問題を知りました。解決策:寸法を同じに保ちながら、画像の解像度を下げます。 (おそらくPhotoshopを使用しています)。
私のために働いた
CoordinatorLayoutの終了タグを忘れたようです。また、ツールバーをCollapsingToolbarLayoutに配置します
<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:id="@+id/coordinatorLayout"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:fitsSystemWindows="true">
<Android.support.design.widget.AppBarLayout
Android:id="@+id/appbar"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:fitsSystemWindows="true"
Android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<Android.support.design.widget.CollapsingToolbarLayout
Android:id="@+id/collapsing_toolbar"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
Android:id="@+id/backdrop"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:minHeight="100dp"
Android:fitsSystemWindows="true"
Android:scaleType="centerCrop"
Android:src="@drawable/pic"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.5"
app:layout_scrollFlags="scroll|exitUntilCollapsed" />
<Android.support.v7.widget.Toolbar
Android:id="@+id/toolbar"
Android:layout_width="match_parent"
Android:layout_height="?attr/actionBarSize"
Android:background="#da1b75"
Android:orientation="horizontal"
Android:textColor="#ffffff"
Android:theme="@style/ThemeOverlay.AppCompat.Light"
app:layout_anchor="@id/appbar"
app:layout_collapseMode="pin"
app:title="Your title">
</Android.support.v7.widget.Toolbar>
<!-- What is this for?
<include
Android:id="@+id/framelayout"
layout="@layout/header_layout"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
Android:minHeight="100dp"/>
-->
</Android.support.design.widget.CollapsingToolbarLayout>
</Android.support.design.widget.AppBarLayout>
<!-- Your Scrollable View -->
<Android.support.v4.widget.NestedScrollView
Android:id="@+id/nested"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:orientation="vertical"
Android:paddingTop="24dp">
</LinearLayout>
</Android.support.v4.widget.NestedScrollView>
</Android.support.design.widget.CoordinatorLayout>
CoordinatorLayoutとCollapsingToolbarLayoutのスムーズスクロールはバグであり、Googleではまだ修正されていません。 :|
nestedScrollViewを削除します。 app:layout_behavior = "@ string/appbar_scrolling_view_behavior"を使用したRecyclerViewこれで十分です。
サードパーティのライブラリを使用できます: https://github.com/henrytao-me/smooth-app-bar-layout
coordinator layout
とRecyclerView
を含むフラグメントを含むレイアウトで同様の問題に直面していました。スクロールをスムーズにするために、CollapsingToolbarLayout
に次のコードを追加しました。
app:layout_scrollFlags="scroll|enterAlways"
マニフェストファイルにAndroid:hardwareAccelerated = "false"行がある場合は、それを削除します。