0

Here is what I want to do

I am not able to make the upper view scroll with listview. The top view has clickable elements. The top view has different elements like image,text1,text2,table. The bottom layout has ListView. The whole view is wrapped inside Relative Layout.

SaKet
  • 1,638
  • 3
  • 17
  • 20
  • If u wanna scroll listview then it comes with default scroll. – Android Killer Feb 16 '12 at 07:09
  • I know that list are scrollable :-). I want the view above the list to scroll when user scrolls the list. The reason is top view itself could take most of the screen. – SaKet Feb 16 '12 at 07:19
  • 1
    Its not good to use listview in scrollview. Check this [Listview inside Scrollview][1] [1]: http://stackoverflow.com/questions/3495890/how-can-i-put-a-listview-into-a-scrollview-without-it-collapsing – EedAndroid Feb 16 '12 at 07:35
  • Yaa. I don't want to put a listview inside a scrollview. Are there any other solutions ? – SaKet Feb 16 '12 at 07:55
  • You mentioned in G+ "without using addHeaderView" ... why not? – Roman Nurik Feb 16 '12 at 18:39
  • @RomanNurik top view can exist without the listview (like when having 0 comments). Thanks for your response. – SaKet Feb 16 '12 at 18:55
  • 1
    "top view can exist without the listview" -- so? Put it as the header view with an empty `ListAdapter` if there are no comments. – CommonsWare Feb 16 '12 at 18:57
  • @CommonsWare so you mean that its advisable to use Header View in such cases. There is not other alternative? The documentation of headerview says Add a 'fixed' view to appear at the top of the list. I thought it will not scroll. Then I read on one of the google group that youtube app was using headerview to get this behavior. – SaKet Feb 16 '12 at 19:03
  • 1
    "so you mean that its advisable to use Header View in such cases" -- I mean that it is worth trying. "There is not other alternative?" -- you could use my `MergeAdapter`, though it does pretty much the same thing in this case. If you want stuff to scroll with the list, that stuff has to be in the list. – CommonsWare Feb 16 '12 at 20:09
  • Quick update - I used headerview. It works. This option involved lots of refactoring of my code. I will post the answer with layout files in a while. One other reason I didn't want to use listheader view was I wanted the top view to hang on top -just the text in that view as it scrolls. Thanks for your help. – SaKet Feb 16 '12 at 20:19

2 Answers2

0

Here is what I did . Hope it helps others who trip on this stuff.

main_layout.xml (this is encapsulated inside relative layout)

<ListView
    android:id="@+id/comments_list"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_above="@+id/comments_editText"
    android:layout_marginLeft="0dp"
    android:layout_marginRight="0dp"
    android:scrollbarStyle="outsideInset"
    android:cacheColorHint="#00000000"
    android:divider="@color/background_color"
    android:dividerHeight="1dp" />

<EditText
    android:imeOptions="normal"
    android:inputType="text"
    android:id="@+id/comments_editText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_margin="6dp"
    android:text="@string/write_comment" />

Then I created a headerview.xml (encapsulated inside linear layout with android:layout_width="wrap_content" android:layout_height="wrap_content" )

<My_Custom_view>
    android:id="@+id/comments_info"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/comments_likeText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="2dp"
    android:paddingTop="1dp"
    android:paddingLeft="10dp"
    android:scaleType="centerInside"
    android:drawableLeft="@drawable/like_icon"
    android:drawablePadding="4dp"
    android:textColor="@color/dark_blue_text_color"
    android:visibility="gone" />

And then to on my Listfragmet (or listview) I did this

View listHead = LayoutInflater.from(getActivity()).inflate(R.layout.headerview, null);
commentsListView = (ListView)root.findViewById(R.id.comments_list);
commentsListView.addHeaderView(listHead);
SaKet
  • 1,638
  • 3
  • 17
  • 20
-2

Use scroll view. Put list view inside scroll view and it should be scrollable. ps. as stated before, list view should have some kind of default scrolling but it haven't worked for me always.

Ruuhkis
  • 1,924
  • 1
  • 27
  • 46
  • 2
    Its not advisable to put listview inside a scrollview. Romain Guy has mentioned this couple of times. – SaKet Feb 16 '12 at 07:54