0

enter image description here

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="@dimen/recycler_view_padding_top"
            android:paddingStart="@dimen/recycler_view_padding_start"
            android:paddingEnd="@dimen/recycler_view_padding_end" />
        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/button_add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"    
            android:layout_marginEnd="@dimen/fab_horizontal_margin"
            android:layout_marginBottom="@dimen/fab_vertical_margin"
            android:layout_gravity="bottom|end"
            android:src="@drawable/ic_add_button"
            android:visibility="gone"
            app:fabSize="mini"
            app:maxImageSize="@dimen/fab_max_image_size"
            tools:visibility="visible"
            />
    </FrameLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

Above is my RecyclerView which displays list on multiple screen.(One layout displays on multiple screens)

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <RadioGroup
        android:id="@+id/radio1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorAccentSecondary"
        android:orientation="horizontal"
        android:gravity="center"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@id/radio2"
        >

        <Button
            android:id="@+id/button"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="20dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:layout_gravity="center_vertical"
            android:text="@string/label_random_question"
            style="@style/TrainingButtonStyle"
            />

        <Button
            android:id="@+id/button2"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:text="@string/label_start_question"
            style="@style/TrainingButtonStyle"
            />

    </RadioGroup>

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/radio2"
        android:gravity="center"
        android:orientation="horizontal"
        android:background="@color/question_training_background"
        app:layout_constraintTop_toBottomOf="@+id/radio1"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        >
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button3"
            android:layout_gravity="center_vertical"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:text="@string/label_all_question"
            style="@style/TrainingButtonStyle"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button4"
            android:layout_gravity="center_vertical"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:text="@string/label_10_question"
            style="@style/TrainingButtonStyle"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button5"
            android:layout_gravity="center_vertical"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:text="@string/label_20_question"
            style="@style/TrainingButtonStyle"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button6"
            android:layout_gravity="center_vertical"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:text="@string/label_30_question"
            style="@style/TrainingButtonStyle"
            />

    </RadioGroup>
</androidx.constraintlayout.widget.ConstraintLayout>

this is my other View(which contains button) which i have to add at the bottom of RecyclerView not inside.(Only on particular screen not on multiple screen display)

****what can be done so that i can set the view (Containing buttons) at the bottom of the screen? (i am not able to add the view.) ****

1 Answers1

0

Please share some of your code that can be useful to answer as well (as the layout xml).

What you could do is to put into your View a Layout with a given id. Then in your activity set the visibility of the layout you want to hide as "GONE", as:

findViewById<LinearLayout>(R.id.page_layout_3).visibility = View.GONE // this goes into the activity 

See the following example where the LinearLayout with id "page_layout_3" is hide as I wrote. The following layout will generate a page having a Scrollable List and with the navbar at the bottom.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true"
    android:id="@+id/main_layout">

    <LinearLayout
        android:id="@+id/coordinator_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/page_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical">

            <com.google.android.material.button.MaterialButton
                android:id="@+id/connectBtn"
                android:layout_width="250dp"
                android:layout_height="60dp"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="10dp"
                android:layout_marginRight="20dp"
                android:layout_marginBottom="20dp"
                android:gravity="center"
                android:text="Scan">
                ></com.google.android.material.button.MaterialButton>

            <ProgressBar
                android:id="@+id/progress_bar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:visibility="invisible" />

            <ListView
                android:id="@+id/discoveredDevices"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"/>

            <LinearLayout
                android:id="@+id/page_layout_3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center|bottom"
                android:orientation="horizontal">

                <com.google.android.material.button.MaterialButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="BTN 1"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"/>

                <com.google.android.material.button.MaterialButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="BTN 2"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"/>

                <com.google.android.material.button.MaterialButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="BTN 2"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</ScrollView>

You can replace the ListView with your ReciclerView.

UPDATE ANSWER:

Once you have your "recyvleviewlayout.xml" or whatever, you can include it using the Include tag provided by android (https://developer.android.com/training/improving-layouts/reusing-layouts), so you can use or not pending on the activity (screen?) you are in. Make sure you have a layout base where to include it by having a layout for every activity.

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout 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:id="@+id/swipe_refresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <include layout="@layout/recyvleviewlayout"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="bottom"
            android:orientation="vertical">

            <RadioGroup
                android:id="@+id/radio1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center|bottom"
                android:orientation="horizontal"
                app:layout_constraintBottom_toTopOf="@id/radio2"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent">

                <Button
                    android:id="@+id/button"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1"
                    android:text="label_random_question" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="150dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1"
                    android:text="label_start_question" />

            </RadioGroup>

            <RadioGroup
                android:id="@+id/radio2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/radio1">

                <Button
                    android:id="@+id/button3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1"
                    android:text="label_all_question" />

                <Button
                    android:id="@+id/button4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1"
                    android:text="label_10_question" />

                <Button
                    android:id="@+id/button5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1"
                    android:text="label_20_question" />

                <Button
                    android:id="@+id/button6"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="label_30_question" />

            </RadioGroup>
        </LinearLayout>
    </RelativeLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
  • i have added the code for both. the problem is my all 3 different list on different screen uses same layout for recycler view. – Prateek Sharma Jan 20 '22 at 04:26
  • 1
    Do you have 3 screen, do you mean 3 different activities? You can use "" In the activities layout you need to use your reciclerview. I will update the code and it does work. Just tested, if i did not got wrong what you asked for. – antonioaugello Jan 21 '22 at 10:13