Force an ExpandableListView to move other items down - android

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.

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 ListView instead of his Items

I have a layout which is divided in other two layouts: a LinearLayout for the "Header" and a RelativeLayout for the "Content".
In the content layout I have a ListView that needs to grown when the user scrolls, and hide this same ListView behind the header layout.
Basically, I need something like this:
What would be the best aproach to do something like this? This is my layout.xml right now:
<LinearLayout
android:id="#+id/layout_full"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_base"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:weightSum="1"
tools:context=".app.Main">
<!-- Header -->
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".55"
android:background="#drawable/background_header_small"
android:gravity="center_horizontal">
</LinearLayout>
<!-- Content -->
<RelativeLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight=".45">
<ListView
android:id="#+id/listview_full"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/text_add"
android:layout_alignEnd="#+id/text_add"
android:layout_alignStart="#+id/text_add"
android:divider="#null"
android:dividerHeight="0dp"
android:showDividers="none"
android:layout_marginBottom="10dp"
android:footerDividersEnabled="false"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp" />
</RelativeLayout>
</LinearLayout>
Can I somehow remove the elevator component of the ListView, and scroll the ListView instead of the Items inside the ListView?
Apologies, I can't comment yet. But you probably want to use the CoordinatorLayout as your parent, instead of the LinearLayout you're using now. From there you have two options: the hackier way is to use a transparent CollapsingToolbar that is placed underneath the header, the other way is to create your own Behavior that will increase the high/top of the List.
This is under the assumption that the ListView will continue to scroll as normal when the the top of it reaches the top of the screen?
I can throw something together when I get home if this seems like it's on the right track.

Infinite vertical ScrollView

I have a vertical ScrollView and I want to make it infinite. When the last item is shown i want the first item to appear and so one. Anybody can give me some advice?
<ScrollView
android:id="#+id/scrollViewId"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="0.49">
<!-- Right button bar -->
<LinearLayout
android:id="#+id/button_bar"
android:layout_width="#dimen/buttonbar_height"
android:layout_height="match_parent"
android:orientation="vertical"
style="#style/ButtonBar.Bottom">
<ImageButton
android:id="#+id/home"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
style="#style/Widget.Button.Borderless"
android:src="?attr/iconHome"
android:contentDescription="#string/home"/>
<ImageButton
android:id="#+id/movies"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
style="#style/Widget.Button.Borderless"
android:src="?attr/iconMovies"
android:contentDescription="#string/movies"/>
<ImageButton
android:id="#+id/tv_shows"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
style="#style/Widget.Button.Borderless"
android:src="?attr/iconTvShows"
android:contentDescription="#string/tv_shows"/>
</LinearLayout>
I don't know why you want a vertical scrollview with "INFINITE" scrolling! But anyways, my idea of doing is :
For the first time, add the elements in the scrollview. Then, you can find out the end of the scrollview. When end of the scrollview is reached, repopulate the scrollview with the same elements added before under the already populated elements. In this way, whenever the scrollview will come to it's end element, keep populating with more and more elements.
To find the bottom of scrollview, you can refer this
link or similar such links.

ListView not getting space to show content on smaller screens

So I am developing a screen where there are some images and buttons on top and Below that is a list view which shows a list of some activity.
The design is something like this :-
Now on smaller screen the ListView height becomes very small as the screen space is taken up by the above icons and images.
So how can i increase the height of the Linearlayout or ListView so that user can scroll to the see the rest of the ListView.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
.... Other Layouts .....
<ListView
android:id="#+id/listArea"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingLeft="#dimen/list_padding"
android:paddingRight="#dimen/list_padding" />
</LinearLayout>
Edit: Tried using the top view as a header to the List but since I want an EmptyView too, this is creating a problem as it replaces the whole header + listview
From what I read about that issue, you should specify the Views on top as header of the list, and the'll scroll properly.
Afaik this only works if the list is non-empty, as the empty view replaces the whole list including headers.
You can use the weightSum and layout_weight attributes to control how much of the parent's available space a child view will take up. To use these, a parent layout, for example, your LinearLayout, gets the android:weightSum attribute. Each child layout gets the android:layout_weight attribute, where the sum of all child weights is the weightSum of the parent. In addition, each child should have their layout_height or layout_width set to 0dp, whichever is going to be decided by the weight.
Here's an example based on your diagram. Let's say you want the two top views to take up 1/4 of the screen each, and the ListView to take up the bottom half. Add android:weightSum="4" to your LinearLayout, android:layout_weight="1" to the two child layouts that you represent with ...Other Layouts..., and android:layout_weight="2" to the ListView. Code might look something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="4">
<ImageView
android:layout_weight="1"
android:layout_height="0dp"
...some other attributes.../>
<LinearLayout
android:layout_weight="1"
android:layout_height="0dp"
android:orientation="horizontal"
...some other attributes...>
...some children of the LinearLayout...
</LinearLayout>
<ListView
android:id="#+id/listArea"
android:layout_width="match_parent"
android:layout_height="0dp"
android:paddingLeft="#dimen/list_padding"
android:paddingRight="#dimen/list_padding"
android:layout_weight="2"/>
</LinearLayout>

Android: Hidden buttonbar like in Hotmail app

Consider the Hotmail app for Android. When you check an e-mail item, three buttons appear at the bottom: [Mark Read] [Mark Unread] [Delete]
When you uncheck it, the buttons go away again.
What's the layout for this? I've tried this, but it yields scrolling problems at the bottom (can't see last item):
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:color/darker_gray"
android:orientation="horizontal"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:paddingTop="5dip" >
<Button
android:id="#+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:text="#string/mark_read" />
</LinearLayout>
Then, I also need to show/hide this stuff?
Changing the visibility of bottom linearlayout will show/hide it. You'll need to give it an id and then
LinearLayout bottomLayout = (LinearLayout)findViewById(R.id.someId);
bottomLayout.setVisibility(View.GONE)// or View.VISIBLE
As for the scrolling problem, that occurs because the RelativeLayout overlays view components, so you can either show/hide the button overlaying the bottom of the ListView or change the Relativelayout to a LinearLayout so that the ListView ends before the button and change the visibility.
Though I'm not sure this will look very good when you suddenly show the button and the ListView has to resize itself.
Note on visibility
setVisibility(View.GONE);
will remove the view from the layout and other component may resize due to this. However using
setVisibility(View.INVISIBLE);
keeps the space the view took up in the layout and simply makes the view invisible and no resizing will occur.

Categories

Resources