简体   繁体   English

如何使RecyclerView占位符占据垂直空间的其余部分?

[英]How to make placeholder for RecyclerView that takes up rest of vertical space?

I am currently making a RecyclerView with 1 header section and n content sections. 我目前正在制作带有1标头部分和n内容部分的RecyclerView。

__________________
| HEADER         |
|----------------|
| CONTENT_1      |
|----------------|
| CONTENT_2      |
|----------------|
|                |
|                |
|                |
|________________|

However sometimes, I don't have any content and I want to display a message saying "Sorry, you don't have any content right now" - or something like that. 但是有时,我没有任何内容,而是想显示一条消息,“抱歉,您现在没有任何内容”或类似的内容。 But I want that message to be centered in the remaining space. 但是我希望该消息集中在剩余空间中。

__________________
| HEADER         |
|----------------|
|                |
|                |
|                |
| NO_CONTENT_MSG |
|                |
|                |
|                |
|________________|

How would I go about achieving something like this? 我将如何实现这样的目标? I can't seem to figure it out and so right now I am currently just using a fixed height placeholder message - something that I would rather not have. 我似乎无法弄清楚,所以现在我目前仅使用固定高度的占位符消息-我宁愿没有。

__________________
| HEADER         |
|----------------|
| NO_CONTENT_MSG |
|----------------|
|                |
|                |
|                |
|                |
|                |
|________________|

Create something like 创建类似

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="81dp">

<TextView
    android:id="@+id/infotv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:text="No content here"
    android:textSize="25sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
     />

<android.support.v7.widget.RecyclerView
    android:id="@+id/newsA"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    >

</android.support.v7.widget.RecyclerView>

</android.support.constraint.ConstraintLayout>

After that in your code, if you have content 之后,在您的代码中,如果您有内容

infoTV.setVisibility(View.INVISIBLE); 

And if you don`t have content 如果你不满意

infoTV.setVisibility(View.VISIBLE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Native图像会占用所有可用的垂直空间 - React Native image takes up all vertical space available 如何在 Android RecyclerView Android 列表中制作一个占位符项目 - How to make one placeholder items in Android RecyclerView Android list 使RecyclerView后空视图占用剩余空间? - Make empty view take up remaining space after RecyclerView? RecyclerView占用所有屏幕空间 - RecyclerView takes up all screenspace 如何使recyclerview无限滚动(向下/向上)? - how to make a recyclerview infinite scroll (down / up)? RecyclerView GridLayoutManager项目装饰需要测量空间吗? - RecyclerView GridLayoutManager item decoration takes measured space? 使ImageView占用所有可用的垂直空间并增加宽度以在RelativeLayout中按比例放大/缩小 - Make ImageView take up all available vertical space and grow width to scale up/down proportionally in RelativeLayout 对话框中的RecyclerView占用了(几乎)整个区域 - RecyclerView in dialog takes up (almost) whole area 如何使视图不占用任何空间,但在Android RecyclerView中仍然可见? - How to make view not to take any space but still be visible in Android RecyclerView? 如何在Vertical RecyclerView中处理Horizo​​ntal RecyclerView - How to handle Horizontal RecyclerView inside Vertical RecyclerView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM