0

I have a recylcerView inside a Table(Row)Layout, inside a NestedScrollView, all of them have the attribute layout_width set to match_parent. I had the problem that the scrolling of recyclerView didn't work but when trying to get the scrolling done (with NestedScrollView) I figured out that this wasn't the real problem. The problem is the width of my horizontally recylcerView that expands the device widht. I only figured it out, because the row above my recyclerView doesn't display the text correct.

The following image shows the behaviour of RV and the textRow above screenshot

the image to the left: here you can see that the text in the text row above is missing "h word"
the image marked with 2: this is the expected output.

I only achieve the desired "correct" size, if I set layout_width of the recyclerview to "200dp". But I don't want a fixed size (due to different devices).

I tried setting the layout_width of the RV dynamically with the following code without success:

LinearLayoutManager llm = new LinearLayoutManager(this.getContext(), LinearLayoutManager.HORIZONTAL, false);
    mRecyclerViewAttachments.setLayoutManager(llm);
    ViewGroup.LayoutParams params = mRecyclerViewAttachments.getLayoutParams();
    int newWidth = (int) (params.width * 0.9);
    mRecyclerViewAttachments.setLayoutParams(params);

Can anyone help me how to fix this? Below is the complete layout xml of the dialog (the RV comes at last):

<LinearLayout 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_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">

<android.support.v4.widget.NestedScrollView
    android:id="@+id/detail_scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:animateLayoutChanges="true">

    <TableLayout
        android:id="@+id/tableLayoutDetail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1"
        android:paddingLeft="16dp"
        android:paddingRight="16dp">

        <!-- ROW 1 -->
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="8dp"
            android:paddingBottom="8dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingTop="8dp"
                android:paddingBottom="8dp"
                android:layout_weight="1"
                android:gravity="center"
                android:layout_column="0"
                android:layout_span="2"
                android:text="@string/detail_fragment_entry_header_1"
                android:textAppearance="@style/TextAppearance.AppCompat.Body2"
                tools:text="@string/detail_fragment_entry_header_1"
                android:background="@color/colorPrimary"/>

        </TableRow>

        <!-- ROW 2 -->
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="8dp"
            android:paddingBottom="8dp">

            <ImageView
                android:src="@drawable/ic_event_black_24dp"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="left"
                android:layout_column="0"
                />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_column="1"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="left"
                    android:textAppearance="@style/ChronlyTextViewHint"
                    android:text="@string/created_entry"
                    tools:text="@string/created_entry" />

                <TextView
                    android:id="@+id/textViewDate"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="left"
                    android:text="@string/detail_dlg_phone_choose"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body2"
                    tools:text="@string/detail_dlg_phone_choose" />
            </LinearLayout>
        </TableRow>

        <!-- ROW 3 -->
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="8dp"
            android:paddingBottom="8dp">

            <ImageView
                android:id="@+id/imageViewEventType"
                android:src="@drawable/ic_contacts_black_24dp"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="left"
                android:layout_column="0"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_column="1"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="left"
                    android:textAppearance="@style/ChronlyTextViewHint"
                    android:text="@string/detail_dlg_contact"
                    tools:text="@string/detail_dlg_contact" />

                <TextView
                    android:id="@+id/textViewContact"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="left"
                    android:text="@string/detail_dlg_contact_desc"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body2"
                    tools:text="@string/detail_dlg_contact_desc" />
            </LinearLayout>
        </TableRow>

        <!-- ROW 4 -->
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/colorDarkGray"
                android:layout_column="0"
                android:layout_span="2">
            </LinearLayout>
        </TableRow>
        <!-- ROW 5 -->
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingBottom="8dp"
            android:paddingTop="8dp">

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_span="2">

                <android.support.design.widget.TextInputEditText
                    android:id="@+id/editTextComment"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="top|left"
                    android:inputType="textMultiLine"
                    android:scrollbars="vertical|horizontal"
                    android:scrollHorizontally="false"
                    android:overScrollMode="always"
                    android:scrollbarStyle="insideInset"
                    android:hint="Enter a comment"
                    android:textAppearance="@style/TextAppearance.AppCompat.Body2"
                    tools:text="first word, second word, third word, fourth word, fifth word, sixth word, seventh word" />

            </android.support.design.widget.TextInputLayout>
        </TableRow>
        <!-- ROW 6 -->
        <TableRow
            android:id="@+id/rowDetailLabelAttachment"
            android:layout_width="match_parent"
            android:paddingRight="16dp"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:layout_gravity="left"
                android:layout_span="2"
                android:textAppearance="@style/ChronlyTextViewHint"
                android:text="@string/detail_label_attachment"
                tools:text="Attachments"/>
        </TableRow>
        <!-- ROW 7 -->
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="8dp"
            android:paddingBottom="8dp">

            <ImageView
                android:layout_width="48dp"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_attachment_black_24dp"
                android:layout_column="0"
                android:layout_gravity="left"/>
            <!-- https://stackoverflow.com/questions/27083091/recyclerview-inside-scrollview-is-not-working/37338715#37338715 -->

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerViewAttachments"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:scrollbars="horizontal"
                android:overScrollMode="always"
                android:scrollbarStyle="insideInset"
                android:nestedScrollingEnabled="false"
                android:visibility="visible"></android.support.v7.widget.RecyclerView>

        </TableRow>
    </TableLayout>
</android.support.v4.widget.NestedScrollView>

mischi
  • 25
  • 9

1 Answers1

2

Your Tree should be like this

<NestedScrollView>

  <LinearLayout  orientation = vertical>

     <EditText>

     <TextView>

     <Recyclerview>

  </LinearLayout>

</NestedScrollView>
Mubashar Javed
  • 749
  • 1
  • 5
  • 12
  • I thought TableLayout is a good clean choice for it, I will try your solution – mischi Nov 15 '17 at 20:13
  • thank you very much, everything worked. Too easy to think of because I wanted a good and clean design. I was wrong – mischi Nov 15 '17 at 20:28