This question already has answers here:
ListView inside ScrollView is not scrolling on Android
(27 answers)
Closed 3 months ago.
I am having a xml file in which UI elements are arranged in the following sequence. The data I am parsing is being populated on the listView but the listView is not scrollable.Please help me
ImageView
TextView
imageView
ListView
imageView
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView_now_playing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:scaleType="fitXY" />
<TextView
android:id="#+id/textView_DailyLimit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView_now_playing"
android:layout_centerHorizontal="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="2dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/button_PlayArea"
android:layout_marginTop="20dp"
android:background="#ffffff"
android:orientation="vertical" >
<ListView
android:id="#+id/listViewEpisodes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:cacheColorHint="#000000"
android:divider="#android:color/black"
android:dividerHeight="5dp"
android:textColor="#000000" />
</LinearLayout>
<ImageView
android:id="#+id/button_Characters"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1"
android:layout_marginTop="20dp"
android:scaleType="fitXY"
android:src="#drawable/gallery" />
<ImageView
android:id="#+id/button_PlayArea"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView_DailyLimit"
android:layout_marginTop="20dp"
android:scaleType="fitXY" />
</RelativeLayout>
</ScrollView>
You are making a big mistake here by placing the Listview inside Scrollview. Remove Scrollview and UserRelativeLayout as the Top parent and the Listview will scroll.
Also a UX suggestion is never ever use two scrollable items in side
one another as user would never be able to know what has to be
scrolled. And similarly you won't be able to recognize what is user
trying to scroll.
Suggestion
You can do one thing. Just keep your TextView inside the Scrollview and below it keep your listview but don't make the whole layout scrollable. i.e. two elements can be scrolled but not the whole screen with scrollable elements.
Never put a listView inside a scrollView. Never ever.
Watch his great video to know more abt listView
http://www.youtube.com/watch?v=wDBM6wVEO70
ListView does not need inside the ScrollView to make it scrollable because ListView will be scrollable if the content is too long.
You can put listview inside scrollview. See this https://stackoverflow.com/a/18354096/942224
and set this value of listview
yourListView.setExpanded(true);
Related
hello I'm trying to use Recyclerview,
below code results only a blank screen, can you please tell me where I'm going wrong
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top|center_vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/ImageSelectorRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="horizontal" />
<ImageView
android:id="#+id/ImageViewSelectPhoto"
android:layout_width="80dp"
android:layout_height="76dp"
android:src="#drawable/ic_add_a_photo_black_361px"
android:background="#drawable/back"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp" />
</LinearLayout>
Since you have provided
android:layout_width="match_parent"
android:layout_height="match_parent"
for your RecyclerView, its taking the full width and height of your device or parent view. And the ImageView is outside the device screen.
Now you have just declared the RecyclerView in your XML. You need a RecyclerView Row Layout which should define the layout for the RecyclerView items.
To show something in the RecyclerView you can set static data in the Row Layout layout iteself or need to create a RecyclerView adapter and model for dynamic/static data.
You need to make a list item layout for your Horizontal-scrollview and a seperate adapter also for it.
Try adding android:viewfillport="true"
I too asked a similar type of question ,please have a look to it yu will surely get a simple way to implement this .
Horizontal Listview Not Working from github
I think it should be similar to this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top|center_vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/ImageSelectorRecycler"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"/>
<ImageView
android:id="#+id/ImageViewSelectPhoto"
android:layout_width="80dp"
android:layout_height="76dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:src="#android:drawable/ic_dialog_alert"
android:background="#android:color/holo_green_dark" />
</LinearLayout>
I have a main Scrollview layout with a LinearLayout including several elements:
ExpandableListView #1 (1 children for yet)
TextView
ExpandableListView #2 (1 children for yet)
Several text views
The issue I encounter is when I click on any of the ExpandableListView, le display by itself is not expanding.
You can see the non-expanded view in this screen-capture (not clikced yet):
https://plus.google.com/photos/101037819512700772601/albums/5870915782494751761/5870915784486932322
You can see the should be expanded view (once I clicked on the ExpandableListViews) in this screen captures:
https://plus.google.com/photos/101037819512700772601/albums/5870915782494751761/5870915780856077570
There you have my layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ExpandableListView
android:id="#+id/expandableView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ExpandableListView>
<TextView
android:id="#+id/providerNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="ABCDEF1"
android:textSize="25sp"
android:textStyle="bold" />
<ExpandableListView
android:id="#+id/expandableView2"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ExpandableListView>
<TextView
android:id="#+id/providerNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="ABCDEF2"
android:textSize="25sp"
android:textStyle="bold" />
. . .
</LinearLayout>
</ScrollView>
Do you have a solution for my issue?
First things first. You can't nest multiple vertical scrolling views. Otherwise you're going to have a field day trying to override the appropriate touch events to get everything right.
If you need other views to scroll as the list scrolls, you can simply add header/footer views. If you need that to be 'sticky' a cursory Google search came up with Sticky headers library.
I have applied scroll view to the entire layout and that layout has one listview. when running the application in the emulator both scroll views are working one scroll view for entire layout and another scroll view for listview (both works fine). but when i installed my app in the phone only outer scroll view is working scroll view for listview is not working. Can any one please tell me the reason and solution for my problem.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg4"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true" >
<ListView
android:id="#+id/listViewTickets"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp" >
</ListView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginBottom="70dp"
android:orientation="horizontal"
>
<Button
android:id="#+id/btnNew"
android:layout_width="80dp"
android:layout_height="30dp"
android:background="#drawable/btnnew" />
<Button
android:id="#+id/btnUpdate"
android:layout_width="80dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/edit" />
</LinearLayout>
The content of list view is displayed dynamically.
I have found the youtube video Google I/O 2010 - The world of ListView an essential watch. In it it's mentioned to never use multiple scrolling widgets unless they scroll on a different axis.
A list view is already scrollable so you can't add it to a scroll view.
Here's a similar question and an answer from the Google engineer in charge of the ListView:
How can I put a ListView into a ScrollView without it collapsing?
I have a linearlayout with 3 imageView and a listview in vertical orientation.i want to scroll the full screen including the images when the user scrolls the list.is that possible?thanks
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#222222"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ph2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ph1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ph2" />
<ListView
android:id="#+id/ll4_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:cacheColorHint="#00000000" />
</ScrollView>
You definitely don't want to put the ListView inside of the ScrollView, but it's certainly possible to include the images. I would recommend considering putting the layout with the images in a header to the ListView. See addHeaderView. This related SO post may also be of use to you.
You should search api , the scrollView can not be inner more than one child , must has one direct child
I am using following code to display button at the bottom of activity.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
>
<Button android:id="#+id/btnGetMoreResults"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Get more"
/>
</RelativeLayout>
and listview above it. when i display more data in listview this button pannel is moved down.can any one guide me how can i fix it at the bottom of activity?
any help would be appreciated.
The answer selected as correct is faulty, the button will hide the lower part of the list view. The correct way is to declare the button first and position the list above the button.
<Button android:id="#+id/btnGetMoreResults"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Get more"
android:layout_alignParentBottom="true"/>
<ListView
...
android:layout_above="#id/btnGetMoreResults"/>
The android:layout_alignParentBottom attribute has to be declared in an element of the RelativeLayout not in the RelativeLayout himself (unless there is another RelativeLayout as a parent).
You should do something like this, with the ListView inside the RelativeLayout also :
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ListView ...>
<Button android:id="#+id/btnGetMoreResults"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Get more"
android:layout_alignParentBottom="true" />
</RelativeLayout>
If you had, for example, all the scrollable elements in a ScrollView, you should do like the following:
<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"
style="#style/rootElement"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- texts, buttons, images and anything that you want to scroll -->
</ScrollView>
<LinearLayout
android:orientation="vertical"
style="#style/footer"
android:id="#+id/footer"
android:layout_alignParentBottom="true"
>
</LinearLayout>
</RelativeLayout>
Note that if you want the footer to be fixed, then you shouldn't put it in the ScrollView, where the scrollable content will be placed. Make it child of RelativeLayout and set layout_alignParentBottom to true. Maybe you'll need to add a padding at the bottom of the ScrollView in this case (so that the last element do not get hidden by the footer).
The idea is similar for elements other than ScrollView