【发布时间】:2016-07-25 13:04:58
【问题描述】:
Activity 打开时,会显示 RecyclerView 布局的顶部,而不是 Activity 布局的顶部。
活动布局.xml文件:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingTop="20dp">
...
<RelativeLayout/>
<View />
<LinearLayout/>
...
<android.support.v7.widget.RecyclerView
android:id="@+id/venue_place_info_gallery_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"/>
</LinearLayout>
</ScrollView>
创建活动:
RecyclerView galleryRecyclerView = (RecyclerView) findViewById(R.id.venue_place_info_gallery_recycler_view);
galleryRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(gridLayoutColumns, StaggeredGridLayoutManager.VERTICAL));
VenueGalleryAdapter venueGalleryAdapter = new VenueGalleryAdapter(VenuePlaceInfoActivity.this, images);
galleryRecyclerView.setAdapter(venueGalleryAdapter);
适配器非常简单。它在构造函数中接收图像作为参数,以后不能更改数据。 我尝试将各种设置应用到 RecyclerView 布局,但无论有没有它们都一样。例如:
galleryRecyclerView.setNestedScrollingEnabled(false);
galleryRecyclerView.setHasFixedSize(true);
galleryRecyclerView.setLayoutFrozen(true);
galleryRecyclerView.setPreserveFocusAfterLayout(false);
更新:
我在answer of another question 中找到了有关该主题的更多信息。这完全是因为 ScrollView 和 RecyclerView 无法同时存在,即使您将 setNestedScrollingEnabled 设置为 true。但它仍然不能解决我的问题。我需要在图库 RecyclerView 上方放置一些东西,并且我想向下滚动浏览所有图像(而不是将它们放入容器中)。
【问题讨论】:
-
可以附上截图吗?
-
删除 galleryRecyclerView.setPreserveFocusAfterLayout(false);行
-
我已经说过这些附加参数目前已被删除。我之前刚刚尝试过,但它们并没有改变任何东西。
-
@YasinKaçmaz,它应该是一个视频,因为在屏幕截图上显示没有什么有趣的东西。它只是从屏幕顶部开始的画廊。
-
@Galya 我无法想象然后我想要一些视觉效果。对不起,我在糟糕的一天
标签: android layout android-recyclerview