Android layout Android-材质设计库:如何使用折叠工具栏布局
我是android开发新手,正在尝试使用谷歌材料设计库中的CollasingToolbar。我对这整个折叠工具栏还不熟悉,但我遵循了一些在线教程,并根据我的需要制作了一个xml,记住了这些建议。我有一个包含5个片段的viewPager的主活动,现在我希望当用户滚动该活动时,viewPager应该占据全屏,活动的其余部分是折叠工具栏 活动的其余部分有两个图像视图、一个分级栏和一些文本视图。我不确定是否所有这些都与正在折叠的工具栏布局兼容,所以我正在尝试 这就是我想说的。这是我尝试实现Coordinator布局和折叠工具栏之前的屏幕截图 是我希望从应用程序获得的输出类型。本例中viewpager中的选项卡较少,但基本的折叠工具栏布局实现是相同的。以下是应用程序的playstore系列,以防万一:play.google.com/store/apps/details?id=com.kkings.cinematics 以下是我的活动的xml,即当前活动(具有正在折叠的toolar):Android layout Android-材质设计库:如何使用折叠工具栏布局,android-layout,android-toolbar,android-tablayout,android-coordinatorlayout,Android Layout,Android Toolbar,Android Tablayout,Android Coordinatorlayout,我是android开发新手,正在尝试使用谷歌材料设计库中的CollasingToolbar。我对这整个折叠工具栏还不熟悉,但我遵循了一些在线教程,并根据我的需要制作了一个xml,记住了这些建议。我有一个包含5个片段的viewPager的主活动,现在我希望当用户滚动该活动时,viewPager应该占据全屏,活动的其余部分是折叠工具栏 活动的其余部分有两个图像视图、一个分级栏和一些文本视图。我不确定是否所有这些都与正在折叠的工具栏布局兼容,所以我正在尝试 这就是我想说的。这是我尝试实现Coordin
这是此活动产生的结果类型:
i、 stack.imgur.com/hPruf.png
我在java中没有做任何更改。学分或任何其他类都不能显示任何内容。我怀疑这是因为recyclerView和nestedScroll视图之间存在冲突
所以,不管怎样,我在所有的在线教程中都看到,他们在折叠工具栏布局中使用了一个工具栏。所以我尝试做同样的事情,这里是新的XML:
<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="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="@+id/tvDescAppBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompact.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/tvDescCollapsingToolBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="@color/chocolateBrown"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparentColor"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|enterAlways">
<RelativeLayout
android:id="@+id/tvDescTabLayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black"
android:paddingBottom="8dp">
<ImageView
android:id="@+id/tvBackgroundImage"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true" />
<ImageView
android:id="@+id/tvImageMain"
android:layout_width="120dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="100dp"
android:foregroundGravity="left" />
<TextView
android:id="@+id/tvDescHeading"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_below="@+id/tvBackgroundImage"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:layout_toRightOf="@id/tvImageMain"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
android:textColor="@android:color/white"
android:textStyle="bold|italic" />
<RatingBar
android:id="@+id/tvDescRating"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/tvBackgroundImage"
android:layout_marginRight="8dp"
android:layout_marginTop="30dp"
android:gravity="center_vertical"
android:numStars="5"
android:stepSize="0.5"
android:visibility="visible" />
<TextView
android:id="@+id/tvDescIdTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/tvDescReleaseDate"
android:layout_below="@+id/tvDescRating"
android:layout_marginBottom="8dp"
android:layout_toLeftOf="@+id/tvDescId"
android:text="ID: "
android:textColor="#D2D2D2"
android:textSize="15sp"
android:textStyle="italic|bold" />
<TextView
android:id="@+id/tvDescId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/tvDescIdTag"
android:layout_below="@+id/tvDescRating"
android:layout_marginBottom="8dp"
android:layout_marginRight="16dp"
android:textColor="#D2D2D2"
android:textSize="15sp"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/tvDescReleaseDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvDescHeading"
android:layout_marginLeft="20dp"
android:layout_marginTop="8dp"
android:layout_toRightOf="@+id/tvImageMain"
android:textColor="#D6D6D6"
android:textSize="13sp"
android:textStyle="bold" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</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"
android:layout_below="@+id/tvDescAppBarLayout">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tvDescTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
app:tabMode="fixed"
app:tabTextAppearance="@style/Base.TextAppearance.AppCompat.Medium"
app:tabTextColor="@android:color/black" />
<android.support.v4.view.ViewPager
android:id="@+id/tvDescViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@android:color/white" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
这个工具栏让一切都很奇怪,这就是它的样子:
i、 stack.imgur.com/PfqP9.png
此外,logcat没有显示任何错误
我只是想不出我的错在哪里。我已经检查了关于StackOverFlow的所有其他类似问题,到目前为止没有一个解决方案有效
这是我刚才提到的教程:
www.youtube.com/watch?v=ssh09JbQ3nc
我做错了什么
重点在于删除第一个相对值yout
,但它不是
必要&在工具栏
外部添加RelativeLayout
现在应该可以这样做了:
<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="wrap_content"
android:layout_height="wrap_content">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvDescAppBarLayout">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/tvDescViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@android:color/white" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:id="@+id/tvDescAppBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompact.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/tvDescCollapsingToolBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|enterAlways" />
<RelativeLayout
android:id="@+id/tvDescTabLayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp">
<ImageView
android:id="@+id/tvBackgroundImage"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:background="@drawable/bg_intro" />
<ImageView
android:id="@+id/tvImageMain"
android:layout_width="120dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="100dp"
android:background="@drawable/bg"
android:foregroundGravity="left" />
<TextView
android:id="@+id/tvDescHeading"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_below="@+id/tvBackgroundImage"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:layout_toRightOf="@id/tvImageMain"
android:text="This is theheading"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
android:textColor="@android:color/white"
android:textStyle="bold|italic" />
<RatingBar
android:id="@+id/tvDescRating"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/tvBackgroundImage"
android:layout_marginRight="8dp"
android:layout_marginTop="30dp"
android:gravity="center_vertical"
android:numStars="5"
android:stepSize="0.5"
android:visibility="visible" />
<TextView
android:id="@+id/tvDescIdTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/tvDescReleaseDate"
android:layout_below="@+id/tvDescRating"
android:layout_marginBottom="8dp"
android:layout_toLeftOf="@+id/tvDescId"
android:text="ID: "
android:textColor="#D2D2D2"
android:textSize="15sp"
android:textStyle="italic|bold" />
<TextView
android:id="@+id/tvDescId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/tvDescIdTag"
android:layout_below="@+id/tvDescRating"
android:layout_marginBottom="8dp"
android:layout_marginRight="16dp"
android:textColor="#D2D2D2"
android:textSize="15sp"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/tvDescReleaseDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvDescHeading"
android:layout_marginLeft="20dp"
android:layout_marginTop="8dp"
android:layout_toRightOf="@+id/tvImageMain"
android:textColor="#D6D6D6"
android:textSize="13sp"
android:textStyle="bold" />
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tvDescTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@android:color/darker_gray"
app:tabMode="fixed"
app:tabTextAppearance="@style/Base.TextAppearance.AppCompat.Medium"
app:tabTextColor="@android:color/black" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
<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="wrap_content"
android:layout_height="wrap_content">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvDescAppBarLayout">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/tvDescViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@android:color/white" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:id="@+id/tvDescAppBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompact.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/tvDescCollapsingToolBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|enterAlways" />
<RelativeLayout
android:id="@+id/tvDescTabLayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp">
<ImageView
android:id="@+id/tvBackgroundImage"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:background="@drawable/bg_intro" />
<ImageView
android:id="@+id/tvImageMain"
android:layout_width="120dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="100dp"
android:background="@drawable/bg"
android:foregroundGravity="left" />
<TextView
android:id="@+id/tvDescHeading"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_below="@+id/tvBackgroundImage"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:layout_toRightOf="@id/tvImageMain"
android:text="This is theheading"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
android:textColor="@android:color/white"
android:textStyle="bold|italic" />
<RatingBar
android:id="@+id/tvDescRating"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/tvBackgroundImage"
android:layout_marginRight="8dp"
android:layout_marginTop="30dp"
android:gravity="center_vertical"
android:numStars="5"
android:stepSize="0.5"
android:visibility="visible" />
<TextView
android:id="@+id/tvDescIdTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/tvDescReleaseDate"
android:layout_below="@+id/tvDescRating"
android:layout_marginBottom="8dp"
android:layout_toLeftOf="@+id/tvDescId"
android:text="ID: "
android:textColor="#D2D2D2"
android:textSize="15sp"
android:textStyle="italic|bold" />
<TextView
android:id="@+id/tvDescId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/tvDescIdTag"
android:layout_below="@+id/tvDescRating"
android:layout_marginBottom="8dp"
android:layout_marginRight="16dp"
android:textColor="#D2D2D2"
android:textSize="15sp"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/tvDescReleaseDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tvDescHeading"
android:layout_marginLeft="20dp"
android:layout_marginTop="8dp"
android:layout_toRightOf="@+id/tvImageMain"
android:textColor="#D6D6D6"
android:textSize="13sp"
android:textStyle="bold" />
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tvDescTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@android:color/darker_gray"
app:tabMode="fixed"
app:tabTextAppearance="@style/Base.TextAppearance.AppCompat.Medium"
app:tabTextColor="@android:color/black" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>