Button at the bottom of ScrollView with ListView inside - android

I have a layout, something like a page. I have a list view and at the bottom of the list i need to have a button. It has to be under the List View, not sticking at the bottom of the screen. (Like you have to scroll all the way down through the list to get that button.) The structure I am using:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#+id/show_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:dividerHeight="7dp"
android:paddingHorizontal="25dp"
android:scrollbars="none"
android:scrollingCache="false" />
<LinearLayout>
//My button here
</LinearLayout>
</LinearLayout>
</ScrollView>
MAIN ISSUE: Scrolling ends at the last item of ListView, Button stays out of screen. Why is that so? (I tried disabling list scrolling with isVerticalScrollBarEnabled, but it didn't make any difference.)
EDIT: Now, as I switched order of the button and the list, I found out that I am scrolling ListView, not ScrollView, so the issue is I need to do scrolling of ScrollView, not ListView. How to do that?

So I found out that ListView in a ScrollView is a bad practice, I used ListView footer feature instead, having button in the seperate layout, then adding it through code. It works perfectly.

Related

Is It possible to click through a ListView?

I have a ListView over a LinearLayout. There are clickable elements in the LinearLayout and since the ListView is transparent I can see those elements, and would like to be able to click on them, but even though the ListView looks transparent, it behaves as a barrier and doesn't let me click on the elements.
Is there a way I can click through the ListView?
If I change the ListView layout_height to wrap_content, it behaves as I want, but I need it to start with a certain height, so the items will stack at the bottom with android:stackFromBottom="true".
This is an example of how the code looks like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
(Clickable elements)
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:transcriptMode="normal"
android:layout_marginTop="100dp"
android:layout_marginBottom="361dp"
android:stackFromBottom="true"
android:listSelector="#android:color/transparent"/>
</RelativeLayout>
Extend listview and override the onTouch() method and pass it down to the underlying views

Android listview in scrollview, listview scroll when scrollview scrolled specific position

I need Scroll Listview inside Scrollview.
Scrollview has two child view, Relative layout and Listview
And listview is using naver's PullToRefresh library.
I want two function
When scroll-up, scroll about half of Relative layout, pass thru touch event to listview.
When scroll-down, if listview showing first item, realative layout will showing fully. else relative layout must be fixed scroll only listview. And if user had over scroll, pull-to-refresh must be work.
I have example screenshot
https://www.dropbox.com/s/8renmrmw5n8g5em/example.png?dl=0
It actually using in project, protected by NDA. that I censored it.
I had try to requestDisallowInterceptTouchEvent(), it not for me.
My layout xml.
<ScrollView
android:id="#+id/main_doc_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
layout="#layout/main_page_top_scroll_items"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_doc_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:divider="#00FF0000"
android:dividerHeight="0dp"
android:fadingEdge="none"
android:fastScrollEnabled="false"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:smoothScrollbar="true"
android:scrollbars="none"
ptr:ptrFriction="3.0"
ptr:ptrSmoothScrollDuration="400" />
</LinearLayout>
</ScrollView>
Thank you for your kind cooperation.
solved.
I give up to use scroll view.
I using onScrollListener on Listview, change menu's marginTop realtime.

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.

Force an ExpandableListView to move other items down

My layout is a ScrollView with some TextView and other controls and also an ExpandableListView.
What I want to do is When Expanding the ExpandableListView the controls which are below it move down and again upon collapsing, all the controls move up and only Group of Expendables become Visible.
The problem is when using wrap_content for expandView's Height the expanding of it shows nothing and just the indicator (little arrow) shows that it's expanded, and when explicitly use some numbers eg. 200dp, the lowest items of expandView not shown. (Because of using two Scrolling widget together).
Here's my simplified layout.
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardcodedText" >
<LinearLayout>
//some controls
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ExpandableListView
android:id="#+id/lstDrugs"
android:layout_width="match_parent"
//HERE is the point that wrap_content only shows the groups header
android:layout_height=**"wrap_content"**
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:divider="#drawable/dividergradient"
android:dividerHeight="2dp" >
</ExpandableListView>
<Button
android:id="#+id/btnAddDrug"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/lstDrugs"
android:text="Add" />
</RelativeLayout>
</LinearLayout>
I've just found my answer in this thread.
The problem is with using List inside ScrollView. To handle it you should use a layout other than the ScrollView (eg. LinearLayout) and add other widgets as Header and Footer of the list. This would enable the scrolling of the view and also expanding of the List.

Android layout - listview and edittext below

I'm trying to mimic the behaviour of the HTC SMS application (tradional view), where all messages are shown, and an EditTextis shown below. As you can see in the screenshot, when scrolling upwards, the EditText scrolls away at the bottom.
I'm stuck with this, even after reading multiple posts (eg Android Layout with ListView and Buttons and this website: http://www.finalconcept.com.au/article/view/android-keeping-buttons-visible), it's not working as expected.
Thanks to the comments and EditText now showing under ListView, I've managed to have my ListView take all available space and start scrolling once completed. The EditText is showing at the bottom of the screen now - always. I'd like it to disappear at the bottom when I scroll up though - now it remains at the bottom
Current Code:
<?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">
<ListView
android:id="#android:id/android:list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TableLayout
android:layout_weight="0"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow>
<EditText android:id="#+id/newmessagecontent"
android:layout_height="150dp"
android:singleLine="false"
android:gravity="top"
android:layout_width="250dp"
android:layout_alignParentTop="true"
/>
<Button android:layout_height="wrap_content"
android:id="#+id/sendmessage"
android:text="Send"
android:layout_width="wrap_content"
/>
</TableRow>
</TableLayout>
</LinearLayout>
i think what you need to implement here is some sort of modification of the SeparatedListAdapter from Jeff Sharkey from this Article. In this article he not only manages to add two Adapters to a ListView but also explains how to have Headers to separate them if you want (you can remove that part of the code).
So what i mean, is your first Adapter will be the data with It's rows, and the second Adapter will be a dummy one with no data that just points to a View with your controls or whatever.
this way the ListView and what you want to add at the bottom are gonna be all scrollable.
Hope this helps.
A ListView automatically scrolls if all the items in it take up more space than the view provides. What happens if you remove the ScrollView?

Categories

Resources