0

I am currently making a RecyclerView with 1 header section and n content sections.

__________________
| 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 |
|----------------|
|                |
|                |
|                |
|                |
|                |
|________________|
AlanSTACK
  • 5,525
  • 3
  • 40
  • 99

1 Answers1

0

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);
Shevchyk Vitalii
  • 68
  • 1
  • 1
  • 7