Tôi có một hoạt động Android sử dụng CollapsingToolbarLayout bên trong CoordinatorLayout để đạt được thanh công cụ cuộn/thu gọn với hình ảnh làm phông nền/biểu ngữ.Đặt chiều cao ban đầu của hình ảnh sai trong CollapsingToolbarLayout
Hình ảnh được tải từ internet và tôi không biết kích thước của nó trước.
Tôi muốn thanh công cụ có chiều cao nhất định (160dp) ban đầu, nhưng nếu hình ảnh lớn hơn thì tôi muốn cho phép người dùng cuộn xuống hơn nữa để hiển thị phần còn lại của hình ảnh. Tuy nhiên, điều này sẽ không bao giờ xảy ra tự động. Trạng thái ban đầu có chiều cao 160dp nhưng người dùng có thể cuộn xuống để tăng chiều cao của hình ảnh.
Tôi dường như không thể tìm thấy sự kết hợp chính xác của chiều cao/minheight để đạt được điều này. Điều này thậm chí có thể ở tất cả?
Dưới đây là cách bố trí của tôi:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@color/toolbar_text">
<android.support.design.widget.CoordinatorLayout
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/appBarLayout"
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"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
android:fitsSystemWindows="true">
<!-- The background banner -->
<ImageView
android:id="@+id/imgBanner"
android:layout_width="match_parent"
android:layout_height="160dp"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
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"
app:theme="@style/AppToolbarTheme" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
...
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
Chiều cao của hình ảnh biểu ngữ được thiết lập để 160dp kiểm soát như thế nào lớn thanh công cụ là bước đầu, nhưng rõ ràng cách này, tôi không thể mở rộng nó vượt ra ngoài 160dp bởi vì đó là chiều cao của chế độ xem.
Tôi đã thử đặt chiều cao 160dp thành CollapsingToolbarLayout
hoặc AppBarLayout
nhưng không có gì giúp, chiều cao luôn tối đa 160dp và tôi chỉ có thể cuộn lên (hình ảnh nhỏ hơn) và không xuống, ngay cả khi hình ảnh lớn hơn nhiều và ImageView
được đặt thành tỷ lệ là wrap_content
.
Dưới đây là một bản vẽ của những gì tôi muốn đạt được trong trường hợp nó không phải là rõ ràng:
Tôi đang cố gắng có chính xác điều tương tự. Bạn đã quản lý để làm việc này? –