问题描述
使用的 本教程 实施灵活的空间格局(一个与折叠工具栏)。
Using this tutorial to implement Flexible Space pattern (the one with the collapsing toolbar).
我想达到类似的效果,在棒棒糖联系人活动,这在一开始进入活动时,观看图像标题的一部分:
I'm trying to achieve a similar effect as in the Lollipop Contacts activity, which at the beginning when entering the activity, views a only part of the image header:
然后,用户可以揭示更多它向下滚动图像下方的布局,直到它达到最大:
Then, user can scroll down the layout below the image in order to reveal more of it, until it reaches the maximum:
在我的应用程序,我不能管理,使其工作。
In my app, I can't manage to make it work.
什么情况是,在进入活动时,图像标题是psented它的最大尺寸,AppBarLayout的大小,就像上面的布局,而不像在棒棒堂联系人活动,其中它显示的图像的一部分。
What happens is that when entering the activity, the image header is presented at it's maximum size, the size of the AppBarLayout, just as the layout above, and unlike in the Lollipop Contacts activity, where it shows only part of the image.
这是在code,用于设置AppBarLayout的高度(我想屏幕的宽度是最大高度):
This is the code that sets the height of the AppBarLayout (I want width of screen to be the maximum height):
int widthPx = getResources().getDisplayMetrics().widthPixels;
AppBarLayout appbar = (AppBarLayout)findViewById(R.id.appbar);
appbar.setLayoutParams(new CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.MATCH_PARENT, widthPx));
这是code,它设置RecyclerView。使用scrollToPosition尝试,认为这将解除RecyclerView的看法,但它没有任何效果可言:
And this is the code that sets the RecyclerView. Tried using scrollToPosition, thought it would lift the view of the RecyclerView up, but it has no effect at all:
mRecyclerView = (RecyclerView) findViewById(R.id.activity_profile_bottom_recyclerview);
mRecyclerView.setHasFixedSize(true);
// use a linear layout manager
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
// specify an adapter (see also next example)
if(mAdapter == null){
mAdapter = new ProfileAdapter(this, user, inEditMode);
mRecyclerView.setAdapter(mAdapter);
}
mRecyclerView.scrollToPosition(mAdapter.getItemCount() - 1); // itemCount is 4
这是布局的xml:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.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="0dp" // set programatically
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="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="32dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/header"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_profile_bottom_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<include
layout="@layout/navigation_view"/>
</android.support.v4.widget.DrawerLayout>
请注意:如果我手动滚动下来,RecyclerView下降,揭示更多的图像,它只是不会通过code工作。
Note: If I manually scrolls down, the RecyclerView goes down and revealing more of the image, it just won't work through code.
我觉得scrollToPosition是解决不了问题,没有任何人有任何想法?
I think scrollToPosition isn't the solution, does anyone have any idea?
有关使用enterAlwaysCollapsed标志也许mentioned这里在CoordinatorLayout和appbar部分用了minHeight:
Thought about using enterAlwaysCollapsed flag perhaps as mentioned here in the CoordinatorLayout and appbar section with minHeight:
enterAlwaysCollapsed:当你的观点已经宣布了minHeight,你 使用此标志,您查看只会在其最小高度输入(例如, '折叠'),只有重新膨胀到其满高度时的滚动 鉴于已经达到了它的顶部。
所以,我设置滚动| enterAlwaysCollapsed标志,以我的工具栏,并在了minHeight我RecyclerView,没有工作。然后我试图移动到了minHeight其他布局如AppBarLayout,毫无效果。它只是收缩的图像有时没有整个视图。
So, I set scroll|enterAlwaysCollapsed flag to my toolbar and minHeight in my RecyclerView, which didn't work. Then I tried moving the minHeight to other layouts such as AppBarLayout, nothing worked. It just shrinked the image sometimes without the whole view.
推荐答案
ü需要一个nastedscroolview
可以看到后续的联系教程:
1。 ActionbarMaterialDesign
2. NavigationView
U need a nastedscroolview
can see the follow links tutorials:
1. ActionbarMaterialDesign
2. NavigationView
这篇关于在Android的灵活空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!