1

I have problem with ScrollView. I'm trying to get it in Relative Layout. I have tried some solutions,but nothing works.I tried setting my relative layout's height to match_parent but it doesn't work also. I can get it to work with linear layout but I don't want to use it for some reason.

MY Xml code: `

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                xmlns:app="http://schemas.android.com/apk/res-auto">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="100">
        <LinearLayout
            android:id="@+id/actionbarh"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/helpdesk_color"
            android:orientation="horizontal"
            android:weightSum="100">
            <ImageView
                android:id="@+id/htoolback"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:padding="03dp"
                app:srcCompat="@drawable/ic_back"
                android:tint="#FFFFFF"
                android:layout_gravity="center"
                android:gravity="center" />
            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="83"
                android:textColorHint="#FFFFFF"
                android:layout_gravity="center"
                android:gravity="center"
                android:textSize="@dimen/action_size"
                android:hint="Help Desk"/>
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar1"
                android:layout_height="wrap_content"
                android:layout_width="0dp"
                android:layout_weight="15"
                android:fitsSystemWindows="true"
                android:theme="@style/Theme"
                android:listSelector="@android:color/transparent"
                app:popupTheme="@style/MyApp.PopupMenu"
                android:gravity="center"
                app:titleTextColor="@color/white"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                />
        </LinearLayout>
        <RelativeLayout
            android:id="@+id/relativelayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="false"
            android:orientation="vertical" >
            <LinearLayout
                android:id="@+id/sublinerlayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:orientation="horizontal">
                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        app:srcCompat="@drawable/ic_profile"
                        android:tint="#000000"
                        android:layout_weight="12"/>
                    <TextView
                        android:id="@+id/hstudentname"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="82"
                        android:textSize="@dimen/large_size"
                        android:textColorHint="#000000"
                        android:gravity="left|center"/>
                </LinearLayout>
            <ScrollView
                android:id="@+id/help"
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:fadeScrollbars="true"
                android:scrollbars="vertical"
                android:layout_marginBottom="80dp"
                android:fillViewport="true">
                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:scrollbars="vertical"
                        android:fillViewport="true"
                        android:fadeScrollbars="true"
                        android:layout_marginBottom="80dp"
                        android:orientation="vertical">
                      <LinearLayout
                          android:id="@+id/idframe"
                         android:layout_width="match_parent"
                         android:orientation="vertical"
                         android:layout_marginLeft="10dp"
                          android:layout_marginRight="10dp"
                          android:padding="2dp"
                         android:background="@drawable/cardviewhelp"
                         android:layout_height="wrap_content">
                          <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="horizontal"
                          ><ImageView
                                    android:layout_width="wrap_content"
                                    app:srcCompat="@drawable/ic_ticket"
                                    android:layout_height="wrap_content" />
                                    <TextView
                                        android:id="@+id/subject"
                                        android:layout_width="match_parent"
                                        android:paddingLeft="05dp"
                                        android:paddingRight="05dp"
                                        android:gravity="left|center"
                                        android:textColor="#000000"
                                        android:textSize="@dimen/large_size"
                                        android:layout_height="match_parent" />
                          </LinearLayout>
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal">
                            <EditText
                                android:id="@+id/comment"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="70"
                                android:textSize="@dimen/medium_m_size"
                                android:paddingLeft="10dp"
                                android:editable="false"
                                android:hint="hint"
                                android:focusable="false"
                                android:scrollbars="vertical"
                                android:gravity="left|center"
                                android:textColorHint="#000000"
                                android:background="#00000000"
                                android:textColor="#000000"/>
                            <TextView
                                android:id="@+id/datetime"
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="30"
                                android:textColor="#000000"
                                android:hint="date"
                                android:textSize="@dimen/medium_m_size"
                                android:gravity="right|bottom"/>
                        </LinearLayout>
                </LinearLayout>
                <LinearLayout
                    android:layout_below="@+id/idframe"
                    android:id="@+id/toolbarframelayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                   >
                   <android.support.v4.widget.SwipeRefreshLayout
                        android:id="@+id/simpleSwipeRefreshLayout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <android.support.v7.widget.RecyclerView
                            android:id="@+id/e_helptoolrecycler"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:scrollbars="vertical"
                            app:stackFromEnd ="true">
                        </android.support.v7.widget.RecyclerView>
                        <!--</LinearLayout>-->
                    </android.support.v4.widget.SwipeRefreshLayout>
                </LinearLayout>
                    </RelativeLayout>
            </ScrollView>
            </LinearLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_marginTop="-80dp"
                android:background="#FFFFFF"
                android:layout_alignParentBottom="true">
                <LinearLayout
                    android:id="@+id/blow12"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:weightSum="100"
                    android:background="#FFFFFF"
                    android:gravity="center"
                    android:layout_gravity="bottom"
                    android:layout_margin="3dp">
                    <EditText
                        android:id="@+id/AddReplay"
                        android:background="@drawable/cardviewhelp"
                        android:layout_width="0dp"
                        android:layout_weight="84"
                        android:hint="Type a Message"
                        android:maxLength="200"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="12dp"
                        android:focusable="true"

                        android:lines="3"
                        android:scrollbars="vertical"
                        android:scrollIndicators="start|end"
                        android:gravity="left|top"
                        android:inputType="textMultiLine|textFilter"
                        android:textColor="#000000"
                        android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890~`\n !@#$%^*()_ -+=|\;;'.,/?"
                        tools:targetApi="m"/>

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_weight="16"
                        android:layout_marginLeft="10dp"
                        android:layout_height="wrap_content">
                        <de.hdodenhof.circleimageview.CircleImageView
                            android:id="@+id/replaybutton"
                            android:layout_width="wrap_content"
                            android:src="@mipmap/send"
                            android:layout_height="wrap_content"
                            app:civ_border_color="#800080"
                            app:civ_border_width="2dp"/>
                    </LinearLayout>

                </LinearLayout>
                <TextView
                    android:layout_below="@+id/blow12"
                    android:id="@+id/textcount"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="15dp"
                    android:layout_marginBottom="5dp"
                    android:textColor="@color/helpdesk_color"
                    android:text="200 Character Remaining"/>
            </RelativeLayout>
            <!--<LinearLayout-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="wrap_content"-->
            <!--android:orientation="horizontal"-->
            <!--android:weightSum="100"-->
            <!--android:layout_alignParentBottom="true"-->
            <!--android:background="#FFFFFF"-->

            <!--android:layout_gravity="bottom"-->
            <!--android:layout_margin="3dp">-->
            <!--<com.xw.repo.XEditText-->
            <!--android:id="@+id/AddReplay"-->
            <!--android:background="@drawable/cardviewhelp"-->
            <!--android:layout_width="0dp"-->
            <!--android:layout_weight="85"-->
            <!--android:hint="Type a Message"-->
            <!--android:maxLength="200"-->
            <!--android:layout_height="wrap_content"-->
            <!--android:padding="2dp"-->
            <!--android:layout_alignParentBottom="true"-->
            <!--android:layout_marginLeft="12dp"-->
            <!--android:focusable="true"-->
            <!--android:gravity="left|center"-->
            <!--android:inputType="textMultiLine|textFilter"-->
            <!--android:textColor="#000000"-->
            <!--app:x_disableEmoji="true"/>-->

            <!--<de.hdodenhof.circleimageview.CircleImageView-->
            <!--android:id="@+id/replaybutton"-->
            <!--android:layout_width="0dp"-->
            <!--android:src="@mipmap/send"-->
            <!--android:layout_height="match_parent"-->
            <!--android:layout_weight="16"-->
            <!--android:padding="2dp"-->
            <!--app:civ_border_color="#800080"-->
            <!--app:civ_border_width="2dp"/>-->
            <!--</LinearLayout>-->
        </RelativeLayout>
    </LinearLayout>
    <!--</android.support.v4.widget.NestedScrollView>-->

</RelativeLayout>

`

My problem : scrolling only this below layout.but not working whole scrolling in Relative Layout. `

<LinearLayout
                      android:id="@+id/idframe"
                        android:layout_width="match_parent"
                         android:orientation="vertical"
                         android:layout_marginLeft="10dp"
                          android:layout_marginRight="10dp"
                          android:padding="2dp"
                         android:background="@drawable/cardviewhelp"
                         android:layout_height="wrap_content">
                          <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="horizontal"
                          ><ImageView
                                    android:layout_width="wrap_content"
                                    app:srcCompat="@drawable/ic_ticket"
                                    android:layout_height="wrap_content" />
                                    <TextView
                                        android:id="@+id/subject"
                                        android:layout_width="match_parent"
                                        android:paddingLeft="05dp"
                                        android:paddingRight="05dp"
                                        android:gravity="left|center"
                                        android:textColor="#000000"
                                        android:textSize="@dimen/large_size"
                                        android:layout_height="match_parent" />
                          </LinearLayout>
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal">
                            <EditText
                                android:id="@+id/comment"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="70"
                                android:textSize="@dimen/medium_m_size"
                                android:paddingLeft="10dp"
                                android:editable="false"
                                android:hint="hint"
                                android:focusable="false"
                                android:scrollbars="vertical"
                                android:gravity="left|center"
                                android:textColorHint="#000000"
                                android:background="#00000000"
                                android:textColor="#000000"/>
                            <TextView
                                android:id="@+id/datetime"
                                android:layout_width="0dp"
                                android:layout_height="match_parent"
                                android:layout_weight="30"
                                android:textColor="#000000"
                                android:hint="date"
                                android:textSize="@dimen/medium_m_size"
                                android:gravity="right|bottom"/>
                        </LinearLayout>
                </LinearLayout>

`

3 Answers3

1

RecyclerView itself a ScrollView .

Solution

Call NestedScrollView instead of ScrollView .

STRUCTURE

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
       >

            <android.support.v7.widget.RecyclerView
                android:id="@+id/list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
             />

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

FYI

You should add

recyclerViewOBJ.setNestedScrollingEnabled(false);

If this property is set to true the view will be permitted to initiate nested scrolling operations with a compatible parent view in the current hierarchy. If this view does not implement nested scrolling this will have no effect. Disabling nested scrolling while a nested scroll is in progress has the effect of stopping the nested scroll.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

You should take a scrollview outside of Relative layout

Arjun Solanki
  • 236
  • 1
  • 11
0

Set your Scrollview to NestedScrollView

<android.support.v4.widget.NestedScrollView>
 <android.support.v7.widget.RecyclerView>
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>

In your recyclerview

recyclerView.setNestedScrollingEnabled(false); 
recyclerView.setHasFixedSize(false);
Ranjithkumar
  • 16,071
  • 12
  • 120
  • 159