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);
Related
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>
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.
I want to place a LinearLayout below a FrameLayout which contains a ListView, but the content of the LinearLayout is not shown.
I also tried this out with a surrounding LinearLayout instead of the RelativeLayout without success.
The FrameLayout cannot be changed to different layout type!
The LinearLayout below will be shown and hidden programmatically.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/framelayout_container" >
<ListView
android:id="#+id/content_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#FFFFFF"
android:dividerHeight="1dp"
android:padding="0dp" >
</ListView>
<LinearLayout
android:id="#+id/description_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white" >
<include
android:id="#+id/description_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/included_layout" />
</LinearLayout>
</FrameLayout>
<LinearLayout
android:id="#+id/below_container"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_alignParentBottom="true"
android:background="#33b5e5" >
<include
android:id="#+id/below_layout"
layout="#layout/below_layout"
android:visibility="visible" />
</LinearLayout>
</RelativeLayout>
Any ideas how to get this work?
The problem is your FrameLayout is set to match the parent width and height, so it will leave no room for the LinearLayout beneath it. You would need to revise it to use its layout_height set to wrap_content, and change the inner ListView to do the same.
I tried add TextView to custom activity to display in multiple activities, but nothing is shown.
This is my custom activity code :
LinearLayout layout;
public void SetupFooter() {
layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setGravity(android.view.Gravity.BOTTOM|android.view.Gravity.CENTER_HORIZONTAL);
TextView tv = new TextView(this);
tv.setText("abc");
layout.addView(tv);
}
This is my main_activity xml code that I want to add the footer to :
<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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton
android:id="#+id/btnGoToTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_margin="5dip"
android:background="#drawable/buttongototop"
android:padding="5dip"
android:visibility="gone" />
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:text="TextView" />
</LinearLayout>
<ListView
android:id="#+id/left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/white"
android:choiceMode="singleChoice"
android:headerDividersEnabled="false" />
<ListView
android:id="#+id/right_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/white"
android:choiceMode="singleChoice"
android:headerDividersEnabled="false" />
</android.support.v4.widget.DrawerLayout>
When I call SetupFooter() in extended activities, nothing is shown.
Are there any problems with my code ?
Sorry for my bad English and thanks for helping me!
Edited :
I added this : addContentView(layout, new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
It's shown now but it's not placed at the bottom, how could I make it stay at the bottom ?
You're creating 2 views in your function, a text view and a linear layout. You're adding the text view to the linear layout, but you aren't putting the linear layout anywhere, so it isn't appearing. If you want to add it to the linear layout already in your xml, you need to give it an id so you can get a reference to it with findViewById, then add the text view to that.
I have a scrollable ListView with items (like in http://developer.android.com/resources/tutorials/views/hello-listview.html). I am using an ArrayAdapter for the items and use it as a parameter in setListAdapter. Now I would like to add a button at the bottom of the screen, which does not scroll with the list. Could someone give me some hints or post a code snippet how it could possibly be done?
If your activity extends ListActivity then you need something like this:
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView android:id="#android:id/list"
android:layout_height="0dip"
android:layout_width="match_parent"
android:layout_weight="1" />
<Button android:id="#+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Notice that the listview has a layout_weight set to 1. That will keep the button fixed in its place at the bottom.
you can use a RelativeLayout to fix the button at the bottom of your layout , and add your listView above it like this :
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<Button android:id="#+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<ListView
android:id="#android:id/list"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_above="#id/btn" />
</RelativeLayout>
My solution based on Houcline's solution but ListView always above Button
<CheckBox
android:id="#+id/chbRemoveIfUninstall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_above="#id/chbRemoveIfUninstall"/>