У меня есть макет с видом карты, привязанный к AppBarLayout в CoordinatorLayout.просмотр карты уменьшен с помощью кода, пока он не достигнет желаемого размера, когда я прокручиваю вверх.Панель инструментов внутри AppBarLayout сворачивалась до тех пор, пока не достигла установленной мной высоты
Вот следующие проблемы:
- Когда я прокручиваю до верхней части макета, половина представления карты становится ниже
AppBarLayout
. - Если я использую разные макеты (вместо просмотра карты) - тогда только плавающая кнопка действия не опускается ниже
AppBarLayout
.
Кто-нибудь знает, как можноЯ это исправлю?
Вот мой xml-код:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:src="@drawable/data_bg"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="bottom"
android:paddingRight="5dp"
app:contentInsetStartWithNavigation="0dp"
app:layout_collapseMode="pin"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:clipToPadding="false"
android:scrollbars="none"
android:scrollingCache="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="vjdsflkjsdfjdsfj;adsjfjdsfl \n
kjsdfjdsfj;adsjfjdsflkjsdfjdsfj;adsjf"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.CardView
android:fitsSystemWindows="true"
android:id="@+id/my_card"
android:layout_width="@dimen/_270sdp"
android:layout_height="150dp"
android:layout_marginTop="-20dp"
android:clickable="true"
app:layout_collapseMode="parallax"
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom|center" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
></LinearLayout>
</android.support.v7.widget.CardView>
</android.support.design.widget.CoordinatorLayout>
Вот мой java-код для масштабирования:
((AppBarLayout) view.findViewById(R.id.app_bar_layout)).addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
int min_height = ViewCompat.getMinimumHeight(collapsing_toolbar) * 2;
float scale = (float) (min_height + verticalOffset) / min_height;
if (scale >= 0.6)
cardView.setScaleY(scale >= 0 ? scale : 0);
});
После того, как просмотр карты опустится ниже AppBarLayout
:
![enter image description here](https://i.stack.imgur.com/dejKu.png)
введите описание изображения здесь