[英]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.