0

I am trying to create a posting fragment. It basically has a LinearLayout containing a TextInputLayout for text input, posting buttons, etc., and a RecyclerView to display posts. At the top of the page, users can write text in a multi-line EditText with a maximum of six lines. The issue is that when I type in the EditText, I can't scroll within it, but I can scroll the entire page. I want to be able to scroll both the RecyclerView and the EditText separately. How can I achieve this?

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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:scrollbars="vertical"
    android:overScrollMode="always"
    >

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:background="@color/lightBlue"
            android:padding="12dp"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="8"
                android:orientation="horizontal">

                <com.google.android.material.imageview.ShapeableImageView
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginTop="6dp"
                    android:layout_marginRight="4dp"
                    app:shapeAppearance="@style/ShapeAppearance.Material3.Corner.Full"
                    android:background="@color/white"
                    android:src="@drawable/friends"
                    />

                <com.google.android.material.textfield.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/til_postLayout"
                    style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense"
                    app:boxBackgroundColor="@android:color/transparent"
                    app:boxBackgroundMode="outline"
                    android:background="@android:color/transparent"
                    app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.Medium"
                    app:counterEnabled="true"
                    app:counterMaxLength="270"
                    app:counterTextAppearance="@style/TextAppearance.AppCompat.Body1"
                    app:helperText="max 270 characters"
                    app:endIconMode="clear_text"

                    >
                    <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/et_post"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="what do you think?"
                        android:inputType="textMultiLine"
                        android:minLines="6"
                        android:maxLines="6"
                        android:paddingTop="4dp"
                        android:gravity="top"
                        android:padding="14dp"
                        app:counterTextAppearance="@style/TextAppearance.MaterialComponents.Body2"
                        android:scrollbars="vertical"
                        android:overScrollMode="ifContentScrolls"
                        />
                </com.google.android.material.textfield.TextInputLayout>

            </LinearLayout>


            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/linearLayout"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2"
                android:gravity="end|start">

                <com.google.android.material.button.MaterialButton
                    android:id="@+id/materialButtonAddImage"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:icon="@drawable/baseline_add_photo_alternate_24"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    style="@style/Widget.Material3.Button.IconButton"
                    />
                <com.google.android.material.button.MaterialButton
                    android:id="@+id/materialButtonLink"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:icon="@drawable/baseline_add_link_24"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toEndOf="@id/materialButtonAddImage"
                    app:layout_constraintTop_toTopOf="parent"
                    style="@style/Widget.Material3.Button.IconButton"
                    />
                <com.google.android.material.button.MaterialButton
                    android:id="@+id/materialButtonShareOpportunity"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    tools:text="herkes"
                    android:textSize="10sp"
                    app:icon="@drawable/baseline_public_24"
                    app:iconGravity="textStart"
                    app:iconPadding="4dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toStartOf="@id/materialShareButton"
                    app:layout_constraintTop_toTopOf="parent"
                    android:layout_marginRight="2dp"
                    style="@style/Widget.Material3.Button.OutlinedButton"/>

                <com.google.android.material.button.MaterialButton
                    android:id="@+id/materialShareButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="10sp"
                    android:text="share"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
            </androidx.constraintlayout.widget.ConstraintLayout>


        </LinearLayout>

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv_post"
            android:layout_width="match_parent"
            android:layout_height="1000dp"
            android:nestedScrollingEnabled="true"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            tools:itemCount="10"
            tools:listitem="@layout/row_post" />
    </LinearLayout>

</androidx.core.widget.NestedScrollView>

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.