android two listview one below the other - android

I have the two listviews listview2 and listview3
what i want is listview3 should be displayed below listview2 but it gets overlapped
How can i get the correct output i.e to be displayed one below the other
and last ListView is navigation drawer
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview2"
android:layout_width="match_parent"
android:layout_height="match_parent"
></ListView>
</RelativeLayout>
<RelativeLayout
android:layout_below="#id/container"
android:id="#+id/container1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview3"
android:layout_width="match_parent"
android:layout_height="match_parent"
></ListView>
</RelativeLayout>
<ListView
android:id="#+id/drawerlist"
android:background="#0099CC"
android:cacheColorHint="#00000000"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left" ></ListView>
</android.support.v4.widget.DrawerLayout>

Use LinearLayout with weight attribute.
<LinearLayout
android:id="#+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"/>
<ListView
android:id="#+id/listview3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5" />
</LinearLayout>

The first RelativeLayout takes the full height of the screen. You'll need to limit the height of the first RelativeLayout otherwise the second RelativeLayout will always be out of the View.

**Its overlapping because:
1. you are setting the height of the list to : match_parent
There is no reference given in relative layout**
Try this:
<RelativeLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>
<ListView
android:id="#+id/listview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/listview1"></ListView>
<ListView
android:id="#+id/listview3"
android:layout_below="#id/listview2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
></ListView>
</RelativeLayout>

You can use layout_weight property to make both listview same height.
For example, you can follow below hierarchy -
<LinearLayout orientation="vertical">
<ListView layout_weight=1></ListView>
<ListView layout_weight=1></ListView>
</LinearLayout>

Nest both ListViews in the same relative layout block, one right after the other. Give them both the same weight
<RelativeLayout
android:id="#+id/container
...
<ListView
android:id="#+id/listview2"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
...
></ListView>
<ListView
android:id="#+id/listview3"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:layout_below="#id/listview2"
...
></ListView>
</RelativeLayout>
I haven't been able to test this, so it may need a few tweaks, but give it a shot.
I would also recommend spending some time formatting your code when you post it because it helps us try to figure out what you're doing.

Taken from https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html
To use a DrawerLayout, position your primary content view as the
first child with a width and height of match_parent. Add drawers as
child views after the main content view and set the layout_gravity
appropriately. Drawers commonly use match_parent for height with a
fixed width.
So both your second RelativeLayout and drawerlist are drawers. In any case, it's unclear what exactly you want to achieve, so you have to describe that in more detail. If you want listview3 to come up from the bottom and listview2 to make room for it, you will have to use a different layout or set listview3 to a specific height and animate your first RelativeLayout to exactly that height (using ValueAnimator for bottom margin I'd say).
Edit:
After reading a comment of yours, it doesn't seem like something you want to achieve. In that case, what I describe above is the culprit, i.e. the second RelativeLayout being interpreted as a drawer. Make sure you combine your RelativeLayouts to a single layout (preferrably LinearLayout with weights).

Related

How can i remove white blank space from bottom of scrollView in android studio

I used two ListView inside one ScrollView like this. But my problem is that there is a white spcae bottom of the scrollview
`
<ScrollView
android:id="#+id/ss"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#+id/sss"
android:layout_weight="1"
android:fillViewport="true"
android:fadingEdgeLength="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true">
<ListView
android:id="#+id/listView1"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:divider="#null"
android:dividerHeight="1dp"
android:overScrollMode="never"
android:layout_weight="1"/>
<ListView
android:id="#+id/listView"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:divider="#null"
android:dividerHeight="1dp"
android:layout_below="#id/listView1"
android:overScrollMode="never"/>
</RelativeLayout>
</ScrollView>
But last time there you can see too much blank space by notice scroll bar on right
Middle
From top
Help me please. Thank you!
Try to add this
android:fillViewport="true"
and put inner layout height also match_parent.

How to adjust listView's height to a fragment under it

I have an Activity with an ExpandableListView and hidden Fragment under it. When you click on a ListView's child element, fragment becomes visible and appears from the bottom with a smooth animation. The problem is that when fragment appears it overlaps a part of the list, so I can't see elements at the bottom. In order to fix that I assume I could dinamically adjust listView's height as fragment pops up, but I don't know how to do that. Any ideas will be appreciated.
Here's an example of what it looks like before showing the fragment:
And that's what happens after it (and I can't scroll down anymore):
Here's the layout:
<RelativeLayout xmlns:
android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_background"
android:orientation="vertical">
<ExpandableListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="#drawable/list_divider"
android:dividerHeight="1dp"
android:childDivider="#drawable/list_divider"
android:fontFamily="sans-serif-thin"
android:groupIndicator="#null" />
<FrameLayout
android:id="#+id/musicBarContainer"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentBottom="true"
android:clickable="true"
android:fontFamily="sans-serif-thin" />
</RelativeLayout>
Finally found a solution! The trick is that you just need to align the container to the parent bottom, then set your listView's height to match_parent and put it above the container. Since listView takes all the possible height but still have to be above the conatiner it will automatically shrink as fragment appears in the container.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_background"
android:orientation="vertical">
<FrameLayout
android:id="#+id/musicBarContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:clickable="true"
android:fontFamily="sans-serif-thin" />
<ExpandableListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/musicBarContainer"
android:childDivider="#drawable/list_divider"
android:choiceMode="singleChoice"
android:divider="#drawable/list_divider"
android:dividerHeight="1dp"
android:fontFamily="sans-serif-thin"
android:groupIndicator="#null" />
</RelativeLayout>

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.

Android XML: Showing listview above viewpager

i want to show ListView above ViewPager using following code but it shows ViewPager without ListView above it. I used following XML code from the link
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ListView
android:id="#+id/wpedenyo_searched_friends_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:scaleType="fitCenter"
android:listSelector="#drawable/list_row_selector" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top" >
</android.support.v4.view.ViewPager></FrameLayout>
UPDATE
It showing following UI
Here jassmin is the content of ListView. It's showing bellow Tab but i want it above all.
FrameLayouts are meant to hold a single child.
Try LinearLayout or RelativeLayout as the parent instead.
For example, you could make a vertically oriented LinearLayout parent and have the vertical space split evenly between your ListView and ViewPager like so:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#+id/wpedenyo_searched_friends_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#color/list_divider"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:dividerHeight="1dp"
android:scaleType="fitCenter"
android:listSelector="#drawable/list_row_selector"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
If you want one or the other child to take up more vertical space, adjust the layout_weights accordingly.
I recently required something like this, Try using AutoCompleteTextView
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.wpedenyo_searched_friends_list);
textView.setAdapter(adapter);

ListView below scrollview in Android

I am trying to put a ListView below a ScrollView in android. I tried putting them inside a LineaLayout like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frameLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/marketDetailScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
...
</ScrollView>
<ListView android:id="#android:id/list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#FFF"/>
</LinearLayout>
and the ListView doesn't get shown. I also tried putting it inside a RelaviteLayout and still nothing. Can I somehow have a ListView under a ScrollView?
Just to add something. I don't want to split my screen so that I have a half with a ScrollView and another half with a ListView. I want the user to scroll down the ScrollView which apparently is bigger than the screen size and then the ListView should start
I would recommend you to put the ScrollView Content as HeaderView in the ListView or do you explicitly want to have two separated scrollable areas on screen?
Example for putting the content of the scroll view in the list view as header (one single scrollable area):
public void onCreate(Bundle s){
setContentView(R.id.yourLayout);
ListView listView = (ListView) findViewById(R.id.listView);
// Set the adapter before the header, because older
// Android version may have problems if not
listView.setAdapter(new YourAdapter());
// Add the header
View header = inflater.inflate(
R.layout.you_layout_that_was_in_scrollview_before, null, false);
listView.addHeaderView(header);
}
The layout of the activity would look like that:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView android:id="#+id/listView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#FFF"/>
</LinearLayout>
If you want two scrollable areas, you should work with layout weight:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/marketDetailScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<!-- ScrollViewContent -->
</ScrollView>
<ListView android:id="#android:id/list"
android:layout_height="0dp"
android:layout_width="match_parent"
android:background="#FFF"
android:layout_weight="1"/>
</LinearLayout>
Fill parent wont work for you,
change it to wrap content, and give layout_weight 1 to scroll view also, then it may work for you
Normally it is not good to put listview in scrollview. but if in case it is required, you need to set the height of listview. Follow the link below to calculate the height of listview for fitting in scrollview.
http://www.jiramot.info/android-listview-in-scrollview-problem
Using this way you can achieve what you want
You have to set the the height of the content of scrollview and its element to 'wrap content'. XML will be like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frameLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/marketDetailScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
...(height will be wrap_content for inner element as well)
</ScrollView>
<ListView android:id="#android:id/list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="#FFF"
android:layout_weight="1"/>
</LinearLayout>
This will might help you..
I think this is near to what you are looking for. I give you this code code but i have to tell that putting a ListView in a ScrollView is a bad-practice and you should not use this solution. You should work on something more correct and with no scroll view within scroll view.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:id="#+id/containerScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/scrollViewContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ScrollView
android:id="#+id/marketDetailScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/scrollViewContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- the views contained in your ScrollView goes here -->
</LinearLayout>
</ScrollView>
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF" />
</LinearLayout>
</ScrollView>

Categories

Resources