【发布时间】:2018-08-16 15:50:12
【问题描述】:
我目前有一个带有recylerView 和actionBar 的透明片段。我正在尝试在我的recylerView 顶部创建一个空间,以便在查看 recylerView 顶部时我的actionBar 不会立即与我的recylerView 重叠。这是我试图创建的效果(取自默认图库应用):
这是我目前在我自己的应用程序中拥有的:
如何在我的 recylerView 之前获得顶部的那个小空白,以便我的透明 actionBar 不会立即与最顶部的 recylerView 行重叠?
这是相关代码:
ActivityMain.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.fragment_container);
if (fragment == null) {
fragment = FragmentAlbumGallery.newInstance();
fm.beginTransaction().add(R.id.fragment_container, fragment, Constants.FRAGMENT_ALBUMS_GALLERY).commit();
}
}
FragmentAlbumGallery.java:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_recycler_gallery, container, false);
mAlbumRecyclerView = (RecyclerView) v.findViewById(R.id.recycler_view);
mAlbumRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
//onResume() gets called here. No need to set up adapter since we do it there
// setupAdapter();
return v;
}
activity_fragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark">
</FrameLayout>
fragment_recyler_gallery.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ActivityGallery"/>
【问题讨论】:
-
您是否尝试过在您的回收站视图上添加等于操作栏高度的填充顶部?
-
您的活动 XML 是什么样的?
-
是的,我确实有!当我将填充添加到我的 recylerview 顶部时,操作栏不再透明!
-
看看this教程。
-
你的问题没有完整的代码,它没有告诉你如何在你的活动中设置工具栏。
标签: android android-layout android-recyclerview android-actionbar