i am using expandable list view in my application. my application consists images, buttons and expandable listview. Here i want to add scroll view in dynamically while expandable list view text is visible otherwise no need to show scroll view in my layout.
Any one can help me how to do this thing.
Put the whole layout under Scroll View but don't forget scroll view accept only one child so you can do like following:
<ScrollView>
---
...
<LinearLayout>
---
---
---
</LinearLayout>
<ScrollView>
For example:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/leatherbackground" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
----- Your xml code.....
</RelativeLayout>
</ScrollView>
Related
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
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.
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?.
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.
It's an old and old question.Listview locates inside the scrollview beside a linearlayout.
Maybe there are tow solutions:
1.give up using it.
2.confirm the height of listview or make the height dynamic.While,when I code in this way,I find the focus is always on the bottom of the listview.And request.setFocus() donen't work....
How to deal with it??
You should not place the list view inside a ScrollView. If you want to show something above or below the list and want to scroll them together the list, you just need to use header or footer views.
An example:
The main screen content:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
The footer view (list_footer.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"><!-- the footer content -->
</LinearLayout>
Adding footer in code: You should do it before setting an adapter for the list
ListView listView = (ListView) view.findViewById(R.id.main_list);
View footer = LayoutInflater.from(getActivity()).inflate(R.layout.list_footer, listView, false);
listView.addFooterView(footer);
listView.setAdapter(yourAdapter);
A ScrollView can only hold a child. If that Linearout is really necessary(usually it's just a holder), you should do this:
<ScrollView>
<LinearLayout>
<ListView>
<!-- Blahblah -->
</ListView>
<LinearLayout>
<!-- Blahblah -->
</LinearLayout>
</LinearLayout>
</ScrollView>