Disabling the scroll of ListView inside a ScrollView - android

I have a ScrollView. Inside it I have a list view which has its own scroll mechanism. However I have certain items inside the list view which works only with the listView scroll i.e not all the items are displayed of the list view inside the parent layout.
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
// SOME CODE
<ListView
android:id="#+id/latsttrans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1" >
</ListView>
// SOME CODE
</ScrollView>
I want to disable the scroll of listview so that I can access the parent layout and the listview items with the ScrollView itself.
Any ideas ?

Try LinearLayout instead of ListView and add child views in linear layout using addChild() method of LinearLayout. Inflate views using LayoutInflater and add those to LinearLayout.

Related

Second list view not expanding in linear layout fragemnt

My linear layout having two list views, when i add items in second list view, its not expanding. its getting scrolled automatically,
i have used match_parent in my linear layout, even though the second list view (getting scrolled instead of expanding) or the linear layout is not expanding.
Can anyone please help me to expand the list view or the linear layout.
problem in linear layout or the second list view?
but the first list view expanding properly.
fragment_one.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:descendantFocusability="blocksDescendants"
android:padding="10dip" >
<ListView
android:id="#+id/list_nation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="#B29090"
android:nestedScrollingEnabled="true">
</ListView>
<ListView
android:id="#+id/list_regional"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:background="#4A9C67"
android:focusable="false"
android:nestedScrollingEnabled="true">
</ListView>
</LinearLayout>
When you add multiple scrolls in a single screen it always shows problems. Because they conflict with each other.
There are two solution for your problem.
If you want to keep your each listview to take half screen then add "weightsum = 100" in your main linear layout and set weight of both listviews to "50".
If you want your first list to scroll till end and at the end of first you want the second one to start scrolling, then calculate the height of your lists on run time and assign the calculated height to your listviews. Check this: Android: How to measure total height of ListView

scroll both parent LinearLayout and Listview

I have the following layout
<LinearLayout
android:orientation="vertical"
...
/>
<include .../>
<include .../>
<ListView ... />
</LinearLayout>
Naturally the content of the ListView scrolls. But what I want is for the entire LinearLayout to scroll concurrently with the ListView, appropriately of course: i.e. both should scroll until only the ListView is on screen. I already tried wrapping the LinearLayout with a ScrollView. That's not working
You can inflate a custom view using layout inflater then use this:
myList.addFooterView(myFooter);//for header
myList.addHeaderView(myHeader);//for footer

Scroll listview vertical and horizontal same image

I want design layout same like my attached image, this listview can horizontal and vertical scroll. I create header A B C by gridview, but not add list view in the rest.
Image:
As I understand, you try to put above a ListView, a ScrollView or a GridView another GridView as an HeaderView which this scrolls horizontally. It seems like adding several widgets which have their own handling of scroll event.. Don't know if this is possible.
Try another way, change your GridView as a HorizontalScrollView and put your views A, B, C.. inside.
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
Here, your views A, B, C...
</HorizontalScrollView>
See an example of this simple layout: Scrollabale listview in both direction with header using Horizontal scrollview.
Then if you want to scroll the content but keep the header part fixed, try to add this layout above your content with a ViewGroup container (inside LinearLayout, RelativeLayout or something else) with an include:
<RelativeLayout
... >
<include
android:layout="#layout/layout_horizontal_scrollview"
... >
<ListView
... >
</RelativeLayout>
This should do the trick..
But if you want that your header part scroll at the sime time to your content, try to add this layout as a HeaderView (I've just try this, it works):
Create an HorizontalScrollView for header:
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
Here, your views A, B, C...
</HorizontalScrollView>
Inflate this layout as a HeaderView:
View header = View.inflate(this, R.layout.layout_horizontal_scrollview, null);
listview.addHeaderView(header);
Note: add a HeaderView to a GridView isn't possible, you could do this with a special adapter (like HFGridView).
Compose them (GridView and ListView) in RelativeLayout or vertical oriented LinearLayoutthis way:
<?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" >
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/gridview" >
</RelativeLayout>
Item to ListView is added programmatically by setting data to adapter.
Edit (enabling vertical and horizontal scroll):
Try this How can I make my layout scroll both horizontally and vertically?.

Why is Horizontal Scrolling is not working when a List View is placed inside a horizontal ScrollView?

I have a simple list view which is placed inside a Horizontal Scroll view so that I can scroll horizontally when the list view content is too long. When I place Text View inside the horizontalScrollView, I could scroll horizontally. But, with list view it doesn't work.
Any body had the same issue? Any work around for this?
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/newListBoxContainerHSV"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#FF00FF">
<ListView
android:id="#+id/list_view"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#FFFF00"
>
</ListView>
</HorizontalScrollView>
Because ListView is not meant to be put inside any ScrollView. It's considered a bad practice, as ListView itself has a built-in ScrollView and you may use it, so try avoiding at any price a ListView inside a ScrollView.
If necessary, redesign your layout to not need it, as it goes against Android's design.

HorizontalScrollView considers only first child of nested ListView

I have a ListView thats nested inside a HorizontalScrollView like so:
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<ListView android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</HorizontalScrollView>
In the ArrayAdapter's getView() method I dynamically add TextViews and ImageViews. The underlying data gets set once in the ListActivity's onCreate() method. If the width of one list item exceeds the available space the ScrollView does not scroll, unless it's the first item and the View scrolls only until the right border of the first item is visible.
Is there anything I'm missing?
Try to change your ListView's layout_height value to fill_parent.

Categories

Resources