首页 > 解决方案 > 将 Recylerview 放在透明操作栏下方?

问题描述

我目前有一个带有 arecylerView和 an的片段,actionBar它是透明的。我正在尝试在我的顶部创建一个空间,recylerView以便在查看 recylerView 的顶部时我actionBar不会立即与我重叠。recylerView这是我试图创建的效果(取自默认图库应用):

https://imgur.com/nBuGCnG

这是我目前在我自己的应用程序中拥有的:

在此处输入图像描述

如何在我的 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;
}

活动片段.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"/>

标签: androidandroid-layoutandroid-recyclerviewandroid-actionbar

解决方案


在其下添加一个ViewRecyclerView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#c4c4c4" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom" />

</LinearLayout>

输出:

在此处输入图像描述


推荐阅读