如何在android中制作折叠工具栏? [英] How to make a collapsing toolbar in android?
本文介绍了如何在android中制作折叠工具栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我试图实现一个简单的折叠工具栏,但我认为我的 xml 布局不正确.文本出现在图像中,当我向下滚动时,我无法向上滚动以查看图像.希望大家帮帮忙!
so im trying to implement a simple collapsing toolbar, but I don't think my xml layout is correct. The text is appearing the image and when I scroll down, I can't scroll back up to see the image. Hope you guys can help!
<?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:ignore="RtlHardcoded">
<android.support.design.widget.AppBarLayout
android:id="@+id/cardInfo_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/cardInfo_collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/image_kyoto"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello there"
android:textSize="30dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello there"
android:textSize="30dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello there"
android:textSize="30dp"/> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello there"
android:textSize="30dp"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
这是图片
推荐答案
你的 ImageView 应该有一个名为
Your ImageView should have attribute called
app:layout_collapseMode="parallax"
如果你想将工具栏添加到你的布局中,应该有一个名为
If you want to add Toolbar to your Layout there should be attribute called
app:layout_collapseMode="pin"
最后你错过了 NestedScrollView 的一个属性.
And finally You missed one attribute for NestedScrollView.
app:layout_behavior="@string/appbar_scrolling_view_behavior"
这篇关于如何在android中制作折叠工具栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文