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>
Related
I have a RecyclerView matching the height of the parent layout.
I need to have an item there to function as a footer. Doing this is not the problem when there are a bunch of items in the list.
The problem is to get it to stick to the bottom when there are a few items and it's not enough to enable the scroll. So, if I have, say 1 item plus footer item, how can I display this item at the bottom of the RecyclerView?
Try using android:weight property. Or if you're using RelativeLayout align the footer to the bottom of the parent view
try this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/places_recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<YourView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
YourView is the view where you will actually add the view for your funcionality. Even if there is no items or there is, it will always be on bottom.
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
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 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>
basically I have layout with some views (TextView, editText and buttons) that almost filling the screen and the bottom of these views I have ListVew element.
I'm populating this list on run time.The problem I have that the scrolling of the listView is not working.I tried to have scrolling bar on the whole layout and it did not work.
What is the best way to have listview at the end of your layout?
regards,
red sea
Never put listview,mapview,Webview in scrollview because these views already have scrolling.
I think other view like textview,imageview put in RelativeLayout and this Relativelayout put in scrollview.and complete the tag of scrollview </ScrollView> .now You should add listview below scrollView.
Like.
<ScrollView android:id="#+id/scroll" ...>
<RelativeLayout...>
<TextView... />
<TextView... />
<ImageView... />
</RelativeLayout>
</ScrollView>
<ListView android:layout_below="#+id/#+id/scroll"... />