android - 将 Recylerview 放在透明操作栏下方?
问题描述
我目前有一个带有 arecylerView
和 an的片段,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;
}
活动片段.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"/>
解决方案
在其下添加一个View
和RecyclerView
:
<?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>
输出:
推荐阅读
- postgresql - 通过与 postgresql 中的其他列分组,将多个 JSONArray 行合并为一行
- docker - 如何通过Dockerfile中的脚本动态设置环境变量?
- php - Guzzle 中 curl_multi_exec 的等价物是什么?
- c++ - 将数组索引从一个类传递到另一个 C++
- python - 如何使用 Python 检测 csv 中的列是否包含某个值?
- ios - 如何在 Swift 5 中转换字符串 URL?
- spring - 如何在一个切入点表达式中匹配两个模式
- python - 数据处理python
- python - np.where() 中的多个条件
- gis - 多边形图形填充周围不需要的额外空白