Scrollview inside Listview - android

I have a listview with mulitple rows, one of the rows must be a listview also with multiple rows, but only 2 of them need to be displayed, the rest displayed only on scrolling. i added a ScrollView with a LinearLayout inside the listview int he layout file and I'm adding the contents of the rows in the java file. The ScrollView doesn't seem to scroll well. Is there a better way of achieving this?
This is my layout file.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="1px"
android:layout_height="1px"
android:layout_weight="1"
android:cacheColorHint="#00000000"
android:scrollbars="vertical" >
</ListView>
<RelativeLayout
android:id="#+id/listItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/formImage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY" />
<include layout="#layout/vertical_list_item_title_area" />
</RelativeLayout>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_weight="1">
<LinearLayout
android:id="#+id/childListLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<com.illumemobile.testapp.Classes.SCClasses.SCActivities.SCCustomActivities.SCCustomGallery
android:id="#+id/horizontallistview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:spacing="33dip" />

ScrollViews insides of ListViews are a VERY VERY bad idea. Not only is it confusing to the user, but the system has problems figuring out which View should get the touch events.
I would recommend rethinking about your layout.

I would recommend making a ScrollView, then inside the scroll view, making a LinearLayout. Inside that LinearLayout you could have more LinearLayouts one or more items as children. I think this would get close to what you're trying to do... I prefer using ScrollViews and LinearLayouts rather than trying to deal with ListViews. LinearLayouts are a lot more dynamic than ListViews in my experience.
-Hope this helps

Related

TableLayout being truncated when placed inside ScrollView

I have a TableLayout which is populated dynamically with many rows of data. It contains more data than the screen can hold, so I require it to be scrollable.
My issue is that when I place the TableLayout inside of a ScrollView, it appears to cut off many rows from the top of the TableLayout.
For reference, the full code is here (the question is to cluttered already to fit it all) http://pastebin.com/w7Fi3Bzz
See below for the code related to the issue I'm having
Here is the XML without the ScrollView:
<TableLayout
android:orientation="vertical"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:id="#+id/tbl_statistics"
android:stretchColumns="*"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
>
</TableLayout>
And what it looks like:
And here is the same XML with an enclosing ScrollView:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<TableLayout
android:orientation="vertical"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:id="#+id/tbl_statistics"
android:stretchColumns="*"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
>
</TableLayout>
</ScrollView>
And here is what the table looks like, you can see the top of the table was truncated (it is populated with the same exact data):
I found a similar issue here LinearLayout not expanding inside a ScrollView, but the answers did not help me.
In your current layout:
Remove android:layout_gravity="center" from the TableLayout element.
Add android:layout_weight="1" to the ScrollView element.
Clean and rebuild your project.
Additionally, the fillViewport attribute only works on ScrollViews.
I resolved the same issue only by inserting TableLayout into LinearLayout which is only child of ScrollView. I tried all other variants without success (fillViewport for ScrollView, android:layout_weight="1" for TableLayout).
I used TableLayout to dynamically insert Views to it
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:id="#+id/activity_displayFields_tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" />
</LinearLayout>
</ScrollView>

Android Layout XML: Divider below Listview

Because of the design of the app, I need to do the following:
(I reduced the problem as much as possible - and searched in other answers, but havent found my problem exactly)
As you can see in the picture, I have following components:
Listview
GreenDivider with a fixed size of 1dp
Button-Area
The Listview is on top, the button-area in the bottom and the divider between them. The Listview is variable in its size.
Following is the difficult part:
The divider has always be visible.
The divider has always to be above the button-area. If the listview does not use the entire available space, the divider has to be exactly below the listview. If the Listview uses more space than available, the divider has to be exactly above the button-area. And of course, the listview should be scrollable.
I tried a long time with relative layout and also with weight in linearlayout. If you got a solution, please share your idea with me.
The following is the part of the layout, but it actually does not work as expected:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/notification_action_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/navigation_item_background_selector"
android:divider="#null"
android:dividerHeight="0dp"
android:orientation="vertical" />
</LinearLayout>
<LinearLayout
android:id="#+id/divider_layout"
android:layout_width="fill_parent"
android:layout_height="1dp" >
<include
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
layout="#layout/divider_horizontal_green" />
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|bottom"
android:orientation="vertical" >
<Button
android:id="#+id/notification_action_remove_button"
style="#style/flat_button_red_rounded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_big"
android:paddingLeft="#dimen/margin_big"
android:paddingRight="#dimen/margin_big"
android:text="#string/delete_account" />
</LinearLayout>
</LinearLayout>
Use a relative layout as your top level. set the footer to alignBottom, and the LinearLayout that contains the Listview and the separator to layout_above="#id/footer". I have edited your xml to solve your problem (I think its properly formed but SO isn't the best editor).
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:alignParentTop="true"
android:layout_above="#id/footer">
<ListView
android:id="#+id/notification_action_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/navigation_item_background_selector"
android:divider="#null"
android:dividerHeight="0dp"
android:orientation="vertical" />
<include
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
layout="#layout/divider_horizontal_green" />
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="true"
android:orientation="vertical" >
<Button
android:id="#+id/notification_action_remove_button"
style="#style/flat_button_red_rounded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_big"
android:paddingLeft="#dimen/margin_big"
android:paddingRight="#dimen/margin_big"
android:text="#string/delete_account" />
</LinearLayout>
</RelativeLayout>
I would declare two dividers and give them each an id.
Then, programatically, I would check the size of the list view against the size of its container.
If the listview is bigger than the container I would make the divider parked above the buttons "visible" and the one below the listview "gone"
etc...
Truthfully, I'd probably just align it above the buttons and call it a day.

Clicking on Edittext inside nested Scrollview scrolls outer scrollview

I have a parent horizontalScrollview that contains various layouts. In one particular layout there is a scrollview. Inside that scrollview there is edittext.
Now when I click on any edittext for input, the horizontal scrollview automatically scrolls the screen to some other layout and I am not able to see the current active layout(containing scrollview).
I know nested scrollviews is a bad coding practice but I can not change it in this case as there will be large amount of rework. Is there any workaround for this.
Following is the xml code for main layout containing horizontalscrollview:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<HorizontalScrollView
android:id="#+id/CloudHScrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
and following is the code for one of the child layouts that is inserted later at some stage. This layout contains the scrollview which has edittexts:-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="#drawable/blueoverlay"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="300dp"
android:paddingTop="90dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/edittext"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#null"
android:gravity="right"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/black" />
</LinearLayout>
</LinearLayout>
</ScrollView>
I'm not sure if this will work, but you can try extending outer ScrollView class and handle its onScroll events on your own.
look here:
listening to scroll events horizontalscrollview android
Android: how to listen for scrolling events?
I had the same issue, solved it by adding the following to AndroidManifest.xml file for the corresponding activity.
android:windowSoftInputMode="adjustResize"

Setting ScrollView for my layout

In My Layout I want to set scrollview for a ListView and imageView. I tried as shown in below.
But it did not work. If I remove the Scrollview then I can able to scroll the Listview. The Items in the Listview are added through the code by downloading from Internet.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/firstImage"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:layout_margin="4dp"
android:scaleType="fitXY" />
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="4dip"
android:layout_weight="1"
android:background="#ffffff" />
</LinearLayout>
</ScrollView>
You do not need a scroll view. In any case nested scrolling is not recommended in Android UI.
Simply use ImageView with ListView and set the weight of Listview to be 1.
listview is scrollable so you do not need to use scrollview

ListView ignoring wrap_content

I have a problem with the ListView in Android.
When I set android:layout_height="wrap_content", ListView stays just one or two rows long and I can't find a way to make him "wrapped".
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView android:id="#+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</FrameLayout>
Is there any way to accomplish this? Thanks in advance!
You should never set the height of a ListView to wrap_content. Either set the height to fill_parent or do something like this:
<ListView
android:layout_height="0dp"
android:layout_weight="1"
/>
Source: http://www.youtube.com/watch?v=wDBM6wVEO70&t=40m45s
It appears you're trying to add a header to your listview. Listview has built-in support for headers (and footers). The method for setting a header is listview.addHeader(View view). You can customize the header as needed.
use ExpandableHeightGridView.java of gitHub ExpandableHeightGridView Try for scrollview

Categories

Resources