0

This is my XML file i want to make views scrollable above Listview ...but the problem is when i run the application it only scroll list view not the views above list view Image view with id = groupimage Textview with id = groupname Image view with id = groupuserimage, Text view with id = Groupusername Till post button..??how to do that...???

<?xml version="1.0" encoding="utf-8"?>
<android.widget.RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/Homebg">
        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:background="@color/Text_color"
            android:orientation="vertical"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:id="@+id/grouplayout">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <ImageView
                        android:id="@+id/groupimage"
                        android:layout_height="200dp"
                        android:layout_width="match_parent"
                        android:scaleType="fitXY"
                        android:src="@drawable/post"/>
                    <ImageButton
                        android:id="@+id/editimage"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:src="@drawable/ic_add_a_photo_black_24dp"
                        android:autofillHints="EditImage"/>
                    <TextView
                        android:layout_height="wrap_content"
                        android:layout_width="match_parent"
                        android:id="@+id/groupname"
                        android:fontFamily="sans-serif"
                        android:layout_below="@+id/groupimage"
                        android:textSize="20dp"
                        android:text="MyGroup"
                        android:gravity="center"
                        />
                </RelativeLayout>
                <LinearLayout
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent"
                    android:layout_below="@+id/groupimagenamelayout"
                    android:orientation="horizontal"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp"
                    android:background="@color/commentlayoutbg">
                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <ImageView
                            android:id="@+id/groupuserimage"
                            android:layout_height="50dp"
                            android:layout_width="50dp"
                            android:layout_margin="6dp"
                            android:src="@drawable/avatar"/>
                        <TextView
                            android:layout_height="wrap_content"
                            android:layout_width="match_parent"
                            android:layout_toRightOf="@+id/groupuserimage"
                            android:layout_marginTop="6dp"
                            android:text="Sayed Mujahid Iqbal"
                            android:textSize="18dp"
                            android:id="@+id/groupusername"/>
                        <EditText
                            android:layout_width="match_parent"
                            android:layout_height="100dp"
                            android:layout_below="@+id/groupusername"
                            android:layout_toRightOf="@+id/groupuserimage"
                            android:background="@drawable/groupedittextboxbg"
                            android:hint="Write something about post"
                            android:layout_marginBottom="5dp"
                            android:layout_marginRight="5dp"
                            android:textAlignment="textStart"
                            android:id="@+id/posteditboxtext"/>
                        <Button
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/posteditboxtext"
                            android:layout_alignParentRight="true"
                            android:text="Post"
                            android:background="#00BBFF"
                            android:textColor="@color/Text_color"
                            android:layout_marginBottom="5dp"
                            android:layout_marginRight="5dp"
                            android:textSize="15dp"
                            android:id="@+id/grouppostbtn"
                            android:fontFamily="sans-serif"/>
                        <ImageButton
                            android:layout_height="wrap_content"
                            android:layout_width="wrap_content"
                            android:layout_toRightOf="@id/groupuserimage"
                            android:layout_below="@id/posteditboxtext"
                            android:src="@drawable/ic_photo_black_24dp"
                            android:autofillHints="Upload Image"
                            android:id="@+id/groupimagebtn"/>
                        <ImageButton
                            android:layout_height="wrap_content"
                            android:layout_width="wrap_content"
                            android:layout_below="@id/posteditboxtext"
                            android:layout_toRightOf="@id/groupimagebtn"
                            android:layout_marginLeft="20dp"
                            android:src="@drawable/ic_attach_file_black_24dp"
                            android:autofillHints="Upload File"
                            android:id="@+id/attachfilebtn"/>
                    </RelativeLayout>
                </LinearLayout>
                <ListView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/postlist"
                    android:layout_margin="5dp"
                    android:layout_below="@+id/grouppostbtn"
                    android:background="#ffffff">
                </ListView>
        </LinearLayout>
</android.widget.RelativeLayout>

3 Answers3

1

Use ScrollView or NestedScrollView As base for those Views (Views above ListView).

Afshin
  • 8,839
  • 1
  • 18
  • 53
  • This may lead to performance issues if the ListView has a number of rows https://stackoverflow.com/questions/18367522/android-list-view-inside-a-scroll-view – Xenolion Mar 23 '18 at 16:26
  • Or this https://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android – Xenolion Mar 23 '18 at 16:27
  • @Xenolion But I didn't mean to place `ListView` Inside `ScrollView`. Just views above `ListView`. – Afshin Mar 23 '18 at 16:29
  • Ooooh I have got it. But that way still you will have two views Scroll View on top and list view at the bottom. They wont scroll together remember... – Xenolion Mar 23 '18 at 16:31
  • @Xenolion He didn't say he want scroll them together...or did he? I didn't get if he want to scroll them together from question. – Afshin Mar 23 '18 at 16:32
0

Since your list view is at the bottom, Make another View in the layout folder and copy all the other Views there leaving the current view with only the ListView.

At runtime inflate the other layout and add it as a header View in the ListView using the method

listView.addHeaderView(your_inflated_view);

Little bit of documentation here

Shalu T D
  • 3,921
  • 2
  • 26
  • 37
Xenolion
  • 12,035
  • 7
  • 33
  • 48
0

In order to make a group of views as scrollable you have to use scrollview and make the other view inside. Note: Scroll View can have one direct child. So like in your case you have multiple views to be scrollable. Put all of them in one view hierarchy and add them to your scrollview

enter link description here

Example code:

`<ScrollView
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  //One direct child
  <LinearLayout>
  //all your views inside this linear layout
  </LinearLayout>
</ScrollView>
`