如何为占据垂直 space 其余部分的 RecyclerView 创建占位符?
How to make placeholder for RecyclerView that takes up rest of vertical space?
我目前正在制作一个包含 1
header 部分和 n
内容部分的 RecyclerView。
__________________
| HEADER |
|----------------|
| CONTENT_1 |
|----------------|
| CONTENT_2 |
|----------------|
| |
| |
| |
|________________|
但有时,我没有任何内容,我想显示一条消息说 "Sorry, you don't have any content right now" - 或类似的内容。但我希望该消息以剩余的 space.
为中心
__________________
| HEADER |
|----------------|
| |
| |
| |
| NO_CONTENT_MSG |
| |
| |
| |
|________________|
我将如何实现这样的目标?我似乎无法弄清楚,所以现在我目前只使用固定高度的占位符消息 - 这是我不想拥有的东西。
__________________
| HEADER |
|----------------|
| NO_CONTENT_MSG |
|----------------|
| |
| |
| |
| |
| |
|________________|
创建类似
的东西
<?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>
在你的代码之后,如果你有内容
infoTV.setVisibility(View.INVISIBLE);
如果您没有内容
infoTV.setVisibility(View.VISIBLE);
我目前正在制作一个包含 1
header 部分和 n
内容部分的 RecyclerView。
__________________
| HEADER |
|----------------|
| CONTENT_1 |
|----------------|
| CONTENT_2 |
|----------------|
| |
| |
| |
|________________|
但有时,我没有任何内容,我想显示一条消息说 "Sorry, you don't have any content right now" - 或类似的内容。但我希望该消息以剩余的 space.
为中心__________________
| HEADER |
|----------------|
| |
| |
| |
| NO_CONTENT_MSG |
| |
| |
| |
|________________|
我将如何实现这样的目标?我似乎无法弄清楚,所以现在我目前只使用固定高度的占位符消息 - 这是我不想拥有的东西。
__________________
| HEADER |
|----------------|
| NO_CONTENT_MSG |
|----------------|
| |
| |
| |
| |
| |
|________________|
创建类似
的东西<?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>
在你的代码之后,如果你有内容
infoTV.setVisibility(View.INVISIBLE);
如果您没有内容
infoTV.setVisibility(View.VISIBLE);