listView and ScrollView - android

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

Related

Unable to scroll listView [duplicate]

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);

Android: Issue with several ExpandableListView in my layout

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.

Unable to populate listview with custom rows when component is above listview

I'm having issues with a ListView using custom rows that are loaded from a database.
If, for the list screen, I place a button above the ListView, no visible rows appear in the listview.
However as soon as I remove the button, everything works fine. I want the button (or any other component) to appear above to make it more user friendly. Attached are the two code samples below.
This is the XML file of the ListView Activity that works:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/real_red_dark">
<LinearLayout
android:id="#+id/llMain"
android:layout_height="fill_parent"
android:background="#drawable/real_background"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:gravity="center">
<ListView
android:id="#+android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/llButton"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/no_sessions"
android:textStyle="bold"
android:textSize="18dp"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
However, if I have the Button added above it, it will not show whatsoever:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/real_red_dark">
<LinearLayout
android:id="#+id/llMain"
android:layout_height="fill_parent"
android:background="#drawable/real_background"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:gravity="center">
<Button
android:id="#+id/btnSearch"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:layout_gravity="center_horizontal"
android:layout_marginTop="3dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="15dip"
android:text="Find Sessions"
android:textStyle="bold" />
<ListView
android:id="#+android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/llButton"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/no_sessions"
android:textStyle="bold"
android:textSize="18dp"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
You could try adding the button programmatically as a header view in the listview itself, rather than in the xml layout.
use listView.addHeaderView(View)
http://developer.android.com/reference/android/widget/ListView.html#addHeaderView(android.view.View)
It is better if you use RelativeLayout than LinearLayout,it is also recommended by the android docs.Try to use android:layout_height value as "wrap_content" for ListView and TextView(which you may use to indicate for empty rows),it may help to you.
Something which doesn't look right but I'm assuming it's just a typo in the above...
android:id="#+android:id/list"
...there shouldn't be a + between # and android:. Using #+ is for adding a new resource id of your own, i.e., #+id:. You're also doing the same thing for the TextView...
android:id="#+android:id/empty"
Another thing but not sure it's relevant is you're specifying...
android:layout_below="#+id/llButton"
...I doubt it's the problem as android:layout_below isn't valid for a LinearLayout (it's for RelativeLayout) but there isn't a Button with the id of llButton in your layout. If there was, the + would also be incorrect as you should be specifying an existing id.
Not sure if amending the above would fix things but it could just be that the layout inflation is coming out 'wrong' due to those issues.

How to include Multiple GridView in a Activity(use ScrollView), just displayed one row?

I want to make Activity like this using GridView.
And this Activity have only one scrollbar include all text & gridview.
for it, using scrollview.
<ScrollView>
android:layout_width="fill_parent"
android:layout_height="fill_parent"
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<GridView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<GridView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
I wrote xml and class like attached using ScrollView to have only one
scroll.
GridView has android:layout_height="fill_parent", but just visible one row.
And each GridView has scroll.
Same result layout_height was changed to wrap_content.
Is it bug? or Do I have some mistake? or Is it impossible?
Thanks.
You need to use the parameter weight :
0 for TextView
1 for GridView

Android delete from listview [duplicate]

I have listview that contain checkbox and an image when the checkbox is clikced I show a button at bottom of the screen that perform deletion, but when listview height more ,then the listview some portion move under the button ,so I need an alternative option for delete can anyone help me, I except something like menu?
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:layout_centerHorizontal="true"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:id="#+id/DelPhto"
android:text="Delete" android:layout_alignParentBottom="true" />
<ListView
android:layout_width="280dp"
android:layout_height="fill_parent"
android:id="#+id/list_pictures"
android:layout_alignParentTop="true"
android:layout_above="#+id/DelPhto" />
</RelativeLayout>
Do you mean you wish for the delete button to be always visible even when the list contents are larger than the list control?
If that's the case try setting the layout_weight of your ListView to 1 and see if that solves your problem.
Put ListView in ScrollView (so one will be able to scroll entire list), like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/listView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="singleChoice"
android:headerDividersEnabled="true">
</ListView>
</ScrollView>
</LinearLayout>
I have had a similar issue in the past. I found that using a relative layout and defining the button before the list solved my issues. Lets consider the following.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="#+id/someButtonId"
android:background="#drawable/gray_button"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:layout_alignParentBottom="true"
android:text="#string/some_button_value"
android:textColor="#color/button_text"
/>
<ListView
android:id="#+id/someList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/someButtonId"
/>
</RelativeLayout>
Here I have defined a Relative layout, the layout will occupy the full screen's width and height. I then place the button on the bottom of the RelativeLayout. My expectation is that the list will be placed above the defined button, and fill the remainder of the screen with list contents. Because we are telling the list View to be placed above the button, it will never grow large enough to cover the button causing the list view to mask the button clicks from the user.
hope this helps.

Categories

Resources